$(document).ready(function() {
    setTimeout(function() {
        $("img[sign='lazy']").show().lazyload({
            effect: "fadeIn",
            skip_invisible: false
        });
    },
    500);
    CancelReload();
    var hm = document.createElement("script");
    hm.src = "//hm.baidu.com/hm.js?5268a54e187670ee0953ba36efee746a";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
});
$.fn.scrollFix = function(height) {
    height = height || 0;
    height = height == "top" ? 0 : height;
    return this.each(function() {
        if (height < 0) {
            height = document.documentElement.clientHeight - this.scrollHeight + height;
        }
        var that = $(this),
        oldHeight = false;
        var dir = "top";
        function getHeight() {
            return (document.documentElement.scrollTop || document.body.scrollTop) + height - that.offset().top;
        }
        $(window).scroll(function() {
            if ((document.documentElement.scrollTop || document.body.scrollTop) == 0) {
                $("div[category='chapterfix']").hide();
            }
            if (oldHeight === false) {
                if (getHeight() >= 0) {
                    oldHeight = that.offset().top - height;
                    $("div[category='chapterfix']").hide();
                    $("div[category='chapterfix'][index='" + that.attr("index") + "']").show();
                }
            } else {
                if ((document.documentElement.scrollTop || document.body.scrollTop) < oldHeight) {
                    $("div[category='chapterfix'][index='" + that.attr("index") + "']").hide();
                    if ((that.attr("index") - 1) > 0) {
                        $("div[category='chapterfix'][index='" + (that.attr("index") - 1) + "']").show();
                    } else {
                        $("div[category='chapterfix'][index='" + (that.attr("index") - 1) + "']").hide();
                    }
                    oldHeight = false;
                }
            }
        });
    });
}
$.fn.numeral = function() {
    $(this).css("ime-mode", "disabled");
    this.bind("keypress",
    function(e) {
        var code = (e.keyCode ? e.keyCode: e.which);
        if (!$.browser.msie && (e.keyCode == 0x8)) {
            return;
        }
        return code >= 48 && code <= 57;
    });
    this.bind("blur",
    function() {
        if (this.value.lastIndexOf(".") == (this.value.length - 1)) {
            this.value = this.value.substr(0, this.value.length - 1);
        } else if (isNaN(this.value)) {
            this.value = "";
        }
    });
    this.bind("paste",
    function() {
        var s = clipboardData.getData('text');
        if (!/\D/.test(s));
        value = s.replace(/^0*/, '');
        return false;
    });
    this.bind("dragenter",
    function() {
        return false;
    });
    this.bind("keyup",
    function() {
        if (/(^0+)/.test(this.value)) {
            this.value = this.value.replace(/^0*/, '');
        }
        if (isNaN(this.value)) {
            this.value = 1;
        }
    });
};
$.fn.doScroll = function(options) {
    var defaults = {
        speed: 40,
        rowHeight: 24
    };
    var opts = $.extend({},
    defaults, options),
    intId = [];
    function marquee(obj, step) {
        obj.find("ul").animate({
            marginTop: '-=1'
        },
        0,
        function() {
            var s = Math.abs(parseInt($(this).css("margin-top")));
            if (s >= step) {
                $(this).find("li").slice(0, 1).appendTo($(this));
                $(this).css("margin-top", 0);
            }
        });
    }
    this.each(function(i) {
        var sh = opts["rowHeight"],
        speed = opts["speed"],
        _this = $(this);
        intId[i] = setInterval(function() {
            if (_this.find("ul").height() <= _this.height()) {
                clearInterval(intId[i]);
            } else {
                marquee(_this, sh);
            }
        },
        speed);
        _this.hover(function() {
            clearInterval(intId[i]);
        },
        function() {
            intId[i] = setInterval(function() {
                if (_this.find("ul").height() <= _this.height()) {
                    clearInterval(intId[i]);
                } else {
                    marquee(_this, sh);
                }
            },
            speed);
        });
    });
}
var textSelect = function(o, a, b) {
    var a = parseInt(a, 10),
    b = parseInt(b, 10);
    var l = o.value.length;
    if (l) {
        if (!a) {
            a = 0;
        }
        if (!b) {
            b = l;
        }
        if (a > l) {
            a = l;
        }
        if (b > l) {
            b = l;
        }
        if (a < 0) {
            a = l + a;
        }
        if (b < 0) {
            b = l + b;
        }
        if (o.createTextRange) {
            var range = o.createTextRange();
            range.moveStart("character", -l);
            range.moveEnd("character", -l);
            range.moveStart("character", a);
            range.moveEnd("character", b);
            range.select();
        } else {
            o.setSelectionRange(a, b);
            o.focus();
        }
    }
};
function insertText(obj, str) {
    obj = document.getElementById(obj);
    if (document.selection) {
        var sel = document.selection.createRange();
        sel.text = str;
    } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
        var startPos = obj.selectionStart,
        endPos = obj.selectionEnd,
        cursorPos = startPos,
        tmpStr = obj.value;
        obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
        cursorPos += str.length;
        obj.selectionStart = obj.selectionEnd = cursorPos;
    } else {
        obj.value += str;
    }
    obj.focus();
}
function commonSwitch(category, listtag, type) {
    if ($("div[category='" + category + "'] h5").length > 0) {
        $("div[category='" + category + "'] h5").on("click mousemove",
        function() {
            if (type == 1) {
                $("div[category='" + category + "'] h5").removeClass("activenan ");
                $("div[category='" + category + "'] h5").removeClass("active");
                if ($(this).attr("extra") == 'nan') {
                    $(this).addClass("activenan");
                } else {
                    $(this).addClass("active");
                }
            } else if (type == 2) {
                $("div[category='" + category + "'] h5").removeClass("activenan ");
                $(this).addClass("activenan");
            } else {
                $("div[category='" + category + "'] h5").removeClass("active");
                $(this).addClass("active");
            }
            $(listtag + "[category='" + category + "list']").hide();
            $(listtag + "[category='" + category + "list'][index='" + $(this).attr("index") + "']").show();
        });
    }
}
function secondToTime(unixTime, isFull, timeZone) {
    if (typeof(timeZone) == 'number') {
        unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
    }
    var time = new Date(unixTime * 1000);
    var ymdhis = "";
    ymdhis += time.getUTCFullYear() + "-";
    ymdhis += (time.getUTCMonth() + 1) + "-";
    ymdhis += time.getUTCDate();
    if (isFull === true) {
        ymdhis += " " + time.getUTCHours() + ":";
        ymdhis += time.getUTCMinutes() + ":";
        ymdhis += time.getUTCSeconds();
    }
    return ymdhis;
}
function getDateDiff(dateTimeStamp) {
    var minute = 1000 * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var halfamonth = day * 15;
    var month = day * 30;
    var now = new Date().getTime();
    var diffValue = parseInt(now) - parseInt(dateTimeStamp + "000");
    if (diffValue < 0) {
        return '刚刚';
    }
    var monthC = diffValue / month;
    var weekC = diffValue / (7 * day);
    var dayC = diffValue / day;
    var hourC = diffValue / hour;
    var minC = diffValue / minute;
    if (monthC >= 1) {
        result = parseInt(monthC) + "个月前";
    } else if (weekC >= 1) {
        result = parseInt(weekC) + "周前";
    } else if (dayC >= 1) {
        result = parseInt(dayC) + "天前";
    } else if (hourC >= 1) {
        result = parseInt(hourC) + "个小时前";
    } else if (minC >= 1) {
        result = parseInt(minC) + "分钟前";
    } else {
        result = parseInt(minC) + "分钟内";
    }
    return result;
}
function checkEmail(email) {
    if (!email.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
        return false;
    }
    return true;
}
function checkPhone(phone) {
    if (!phone.match(/^1[3|4|5|7|8][0-9]\d{4,8}$/)) {
        return false;
    }
    return true;
}
$.fn.hoverDelay = function(options) {
    var defaults = {
        hoverDuring: 200,
        outDuring: 200,
        hoverEvent: function() {
            $.noop();
        },
        outEvent: function() {
            $.noop();
        }
    };
    var sets = $.extend(defaults, options || {});
    var hoverTimer, outTimer;
    return $(this).each(function() {
        $(this).hover(function() {
            clearTimeout(outTimer);
            hoverTimer = setTimeout(sets.hoverEvent, sets.hoverDuring);
        },
        function() {
            clearTimeout(hoverTimer);
            outTimer = setTimeout(sets.outEvent, sets.outDuring);
        });
    });
}
function getBookfacePath(_bid, _size) {
    return hs_const_url.bookface + "/" + Math.floor(_bid / 10000) + '/' + Math.floor((_bid % 10000) / 100) + "/" + _bid + "_" + _size + ".jpg";
}
function getUserFacePath(_uid, _size) {
    _uid = Math.abs(_uid);
    _uid = preZeroFill(_uid, 9);
    var dir1 = _uid.substr(0, 3);
    var dir2 = _uid.substr(3, 2);
    var dir3 = _uid.substr(5, 2);
    return hs_const_url.userface + "/" + dir1 + "/" + dir2 + "/" + dir3 + "/" + _uid.substr( - 2) + "_avatar_" + _size + ".jpg";
}
function getBookfaceSafePath(_bid, _size) {
    return hs_const_url.safebookface + "/" + Math.floor(_bid / 10000) + '/' + Math.floor((_bid % 10000) / 100) + "/" + _bid + "_" + _size + ".jpg";
}
function getUserFaceSafePath(_uid, _size) {
    _uid = Math.abs(_uid);
    _uid = preZeroFill(_uid, 9);
    var dir1 = _uid.substr(0, 3);
    var dir2 = _uid.substr(3, 2);
    var dir3 = _uid.substr(5, 2);
    return hs_const_url.safeuserface + "/" + dir1 + "/" + dir2 + "/" + dir3 + "/" + _uid.substr( - 2) + "_avatar_" + _size + ".jpg";
}
function preZeroFill(_num, _size) {
    if (_num >= Math.pow(10, _size)) {
        return _num.toString();
    } else {
        var _str = Array(_size + 1).join('0') + _num;
        return _str.slice(_str.length - _size);
    }
}
function toThousands(num) {
    var num = (num || 0).toString(),
    result = '';
    while (num.length > 3) {
        result = ',' + num.slice( - 3) + result;
        num = num.slice(0, num.length - 3);
    }
    if (num) {
        result = num + result;
    }
    return result;
}
function htmlencode(s) {
    var div = document.createElement('div');
    div.appendChild(document.createTextNode(s));
    return div.innerHTML;
}
function htmldecode(s) {
    return s.replace(/&#60;/g, '<').replace(/&#62;/g, '>').replace(/&amp;/g, '&').replace(/&quot;/g, '/"').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&#39;/g, '"');
}
function jalert(title, content, callback) {
    if ($("#hidPageType").val() == "content") {
        keytype = "alert";
    }
    $("#dialog-message").attr("title", title);
    $("#dialog-message span:eq(1)").text(content);
    $("#dialog-message").dialog({
        modal: true,
        buttons: {
            '确定': function() {
                $(this).dialog("close");
                if ($("#hidPageType").val() == "content") {
                    setTimeout(function() {
                        keytype = "page";
                    },
                    500);
                }
                if (callback != null) {
                    callback();
                }
            }
        }
    });
    if ($("#hidPageType").val() == "content") {
        var topspace = (parseInt($("#contitletop").offset().top) - 3);
        $("div[role='dialog']").css("top", (window.screen.height / 2) - 90);
        $("html,body").animate({
            scrollTop: topspace
        },
        0);
    }
}
function CheckIllegalChar(str) {
    var pattern = /^[\u4E00-\u9FA5a-zA-Z0-9_]+$/;
    if (pattern.test(str)) {
        return true;
    } else {
        return false;
    }
} (function($) {
    $.extend({
        urlGet: function() {
            var aQuery = window.location.href.split("?");
            var aGET = new Array();
            if (aQuery.length > 1) {
                var aBuf = aQuery[1].split("&");
                for (var i = 0,
                iLoop = aBuf.length; i < iLoop; i++) {
                    var aTmp = aBuf[i].split("=");
                    aGET[aTmp[0]] = aTmp[1];
                }
            }
            return aGET;
        }
    })
})(jQuery);
function getFreeHsCoin() {
    if (window.userInfo != undefined) {
        location = "http://app.offer99.com/index.php?pid=y3934837c77b1ba917515d8af0001525&userid=" + window.userInfo.uid;
    } else {
        user_modellogin.showLoginDialog(11);
    }
}
var user_bookshelf = {
    bid: 0,
    showOrder: function(bid) {
        this.bid = bid;
        this.initOrder();
        if ($(".bodybg").css("display") == "none") {
            $(".bodybg").fadeIn(fadeinTime,
            function() {
                $(".bodybg").click(function() {
                    user_bookshelf.closeOrder(0);
                });
                $("#divOrderModel").css("position", "fixed").css("top", "180px").css("z-index", "1001").css("left", "50%").css("margin-left", "-235px");
                $("#divOrderModel").fadeIn(fadeinTime);
            });
        } else {
            $(".bodybg").click(function() {
                user_bookshelf.closeOrder(0);
            });
            $("#divOrderModel").css("position", "fixed").css("top", "180px").css("z-index", "1001").css("left", "50%").css("margin-left", "-235px");
            $("#divOrderModel").fadeIn(fadeinTime);
        }
    },
    closeOrder: function(islogin) {
        $("#divOrderModel").fadeOut(fadeoutTime,
        function() {
            if (islogin == 1) {
                user_modellogin.showLoginDialog(13);
            } else {
                $(".bodybg").fadeOut(fadeoutTime);
            }
        });
    },
    initOrder: function() {
        $("#btnAutoOrder").click(function() {
            user_bookshelf.autoBuyChp();
        });
        $("#btnOrderAll").click(function() {
            user_bookshelf.orderAll();
        });
        if (window.userInfo != undefined) {
            $("#p_balance").html("您的账户余额：" + window.userInfo.money + "红薯币");
            $("#btnAutoOrder").removeClass("inputbtndisable");
            $("#btnOrderAll").removeClass("inputbtndisable");
            $("#btnAutoOrder").attr("disabled", false);
            $("#btnOrderAll").attr("disabled", false);
        } else {
            $("#p_balance").html("登录后才可以订阅，您可以点击<a style='color:red' href='javascript:void(0)' onclick='user_bookshelf.closeOrder(1)'>此处</a>登录");
            $("#btnAutoOrder").addClass("inputbtndisable");
            $("#btnOrderAll").addClass("inputbtndisable");
            $("#btnAutoOrder").attr("disabled", "disabled");
            $("#btnOrderAll").attr("disabled", "disabled");
        }
        $.ajax({
            url: hs_const_url.bookajax,
            type: 'post',
            dataType: 'json',
            data: {
                method: 'getchapterprice',
                bid: user_bookshelf.bid
            },
            beforeSend: function() {},
            success: function(data) {
                if (data.code == 136) {
                    $("#span_firstVipPrice").text(data.firstvipprice);
                    $("#span_bookPrice").text(data.bookprice);
                    if (window.userInfo != undefined) {
                        if (parseInt(data.bookprice) > window.userInfo.money) {
                            $("#btnOrderAll").addClass("inputbtndisable");
                            $("#btnOrderAll").attr("disabled", "disabled");
                            $("#c_orderAllTip").html("余额不足，请<a href='" + hs_const_domain.payHost + "/profile/pay.html' target='_blank' style='color: blue'>充值</a>")
                        } else {
                            $("#btnOrderAll").removeClass("inputbtndisable");
                            $("#btnOrderAll").attr("disabled", false);
                            $("#c_orderAllTip").html("")
                        }
                    } else {
                        $("#c_orderAllTip").html("")
                    }
                    if (parseInt(window.userInfo.money) < parseInt(data.bookprice)) {
                        $("#btnOrderAll").addClass("inputbtndisable");
                        $("#btnOrderAll").attr("disabled", "disabled");
                    } else {
                        $("#btnOrderAll").removeClass("inputbtndisable");
                        $("#btnOrderAll").attr("disabled", false);
                    }
                }
            }
        }).always(function() {});
        $.ajax({
            url: hs_const_url.bookajax,
            type: 'post',
            dataType: 'json',
            data: {
                method: 'getvipcount',
                bid: user_bookshelf.bid
            },
            beforeSend: function() {},
            success: function(data) {
                if (data.code == 138) {
                    $("#c_vipcount").text(data.count);
                }
            }
        }).always(function() {});
        var url = hs_const_url.bookajax;
        $.ajax({
            url: url,
            type: 'post',
            dataType: 'json',
            async: false,
            data: {
                method: 'getautoorderstatus',
                bid: user_bookshelf.bid
            },
            beforeSend: function() {},
            success: function(data) {
                if (data.code == -102) {} else if (data.code == 121) {
                    $("#btnAutoOrder").removeClass("inputbtndisable");
                    $("#btnAutoOrder").attr("disabled", false);
                    $("#btnAutoOrder").attr("value", "关闭自动订阅");
                    $("#c_autoOrderTip").html("<a href='javascript:void(0)' style='color:blue'>已开启</a>");
                } else if (data.code == -137) {
                    $("#btnAutoOrder").removeClass("inputbtndisable");
                    $("#btnAutoOrder").attr("disabled", false);
                    $("#btnAutoOrder").attr("value", "自动订阅");
                    $("#c_autoOrderTip").html("");
                }
            }
        }).always(function() {});
    },
    autoBuyChp: function() {
        var url = hs_const_url.bookajax;
        $.ajax({
            url: url,
            type: 'post',
            dataType: 'json',
            async: true,
            data: {
                method: 'updateautoorderstatus',
                bid: user_bookshelf.bid
            },
            beforeSend: function() {
                $("#btnAutoOrder").attr("disabled", false);
            },
            success: function(data) {
                if (data.code == -102) {
                    user_modellogin.showLoginDialog('');
                } else if (data.code == 121) {
                    $("#btnAutoOrder").removeClass("inputbtndisable");
                    $("#btnAutoOrder").attr("disabled", false);
                    $("#btnAutoOrder").attr("value", "关闭自动订阅");
                    $("#c_autoOrderTip").html("<a href='javascript:void(0)' style='color:blue'>已开启</a>");
                } else if (data.code == -137) {
                    $("#btnAutoOrder").removeClass("inputbtndisable");
                    $("#btnAutoOrder").attr("disabled", false);
                    $("#btnAutoOrder").attr("value", "自动订阅");
                    $("#c_autoOrderTip").html("");
                }
            }
        }).always(function() {
            $("#btnAutoOrder").attr("disabled", false);
        });
    },
    orderAll: function() {
        var submiturl = hs_const_url.bookajax;
        $(".bodybg").fadeOut(fadeinTime,
        function() {
            $("#divOrderModel").fadeOut(0,
            function() {
                $("#dialog-confirm").dialog({
                    resizable: false,
                    height: 180,
                    modal: true,
                    buttons: {
                        "确认": function() {
                            $(this).dialog("close");
                            $.ajax({
                                url: submiturl,
                                type: 'post',
                                dataType: 'json',
                                async: false,
                                data: {
                                    method: "orderchapter",
                                    bid: user_bookshelf.bid,
                                    buyall: 1
                                },
                                beforeSend: function() {
                                    $("#btnOrderAll").attr("disabled", "disabled");
                                },
                                success: function(data) {
                                    if (data.code == "120") {
                                        jalert("通知", data.msg, null);
                                        $("#a_orderAll" + user_bookshelf.bid).html("已订阅");
                                        $("#a_orderAll" + user_bookshelf.bid).attr("href", "javascript:void(0)");
                                    } else if (data.code == "-113") {
                                        jalert("通知", "余额不足，请充值。");
                                    } else if (data.code == "-134") {
                                        jalert("通知", data.msg, null);
                                    } else if (data.code == "-135") {
                                        jalert("通知", data.msg, null);
                                    } else if (data.code == "-136") {
                                        jalert("通知", data.msg, null);
                                    } else if (data.code == "-102") {
                                        jalert("通知", data.msg, null);
                                    }
                                }
                            }).always(function() {
                                $("#btnOrderAll").attr("disabled", false);
                            });
                        },
                        '取消': function() {
                            $(this).dialog("close");
                        }
                    }
                });
            });
        });
    }
}
function CancelReload() {
    if ($("#hidPageType").val() == "commentlist" || $("#hidPageType").val() == "commentdetail") {
        $(document).bind("keydown",
        function(e) {
            e = window.event || e;
            if (e.keyCode == 116) {
                e.keyCode = 0;
                return false;
            }
        });
        $(document).keyup(function(event) {
            switch (event.keyCode) {
            case 116:
                location = location.href;
                break;
            }
        });
    }
};
$(document).ready(function() {
    initContent();
    bindChapterUp();
    bindCount();
    bindFixed();
    bindPhone();
    initFlower();
    initTicket();
    initTrendScroll();
    initCommentChange();
    initWordCount();
    initPregress();
    initAutoChpStatus();
    initFansRank();
    initMyFace();
    initFav();
    setTimeout('initProperties();', 500);
    initBookComment();
    initBookIndex();
});
var keytype = "page";
function bindChapterUp() {
    $("div[category='chapter']").click(function() {
        $("div[category='chapterlist'][index='" + $(this).attr("index") + "']").slideToggle(0,
        function() {
            if ($(this).is(':hidden')) {
                $("div[category='chapter'][index='" + $(this).attr("index") + "']").find(".up").hide();
                $("div[category='chapter'][index='" + $(this).attr("index") + "']").find(".down").show();
            } else {
                $("div[category='chapter'][index='" + $(this).attr("index") + "']").find(".up").show();
                $("div[category='chapter'][index='" + $(this).attr("index") + "']").find(".down").hide();
            }
        });
    });
}
function bindCount() {
    $("#c_mf").html($(".free").length);
    $("#c_total").html($(".free").length + $(".vip").length);
}
function bindFixed() {
    var row = $("div[category='chapter']").length;
    if (row > 0) {
        for (var i = 0; i < row; i++) {
            $($("div[category='chapter']")[i]).scrollFix("top");
        }
    }
}
function showIntro() {
    var content = $("#p_intro").attr("content");
    $("#p_intro").html("<p><b>简介：</b></p>" + unescape(content));
}
function hideIntro() {
    var content = $("#p_intro").attr("hidecontent");
    $("#p_intro").html("<p><b>简介：</b></p>" + unescape(content));
}
function bindPhone() {
    $("#a_phone").hoverDelay({
        hoverEvent: function() {
            $("#divPhoneMask").fadeIn(fadeinTime);
        },
        outEvent: function() {
            $("#divPhoneMask").fadeOut(fadeoutTime);
        }
    });
}
function doFavorite(bid) {
    hideFace();
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        data: {
            method: 'dofavorite',
            bid: bid
        },
        beforeSend: function() {
            $("#a_favdone").text("正在收藏");
            $("#a_favdone").attr("href", "javascript:void(0)");
            $("#spanCancelFav").text("正在取消");
            $("#spanCancelFav").attr("disabled", "disabled");
        },
        success: function(data) {
            if (data.code > 0) {
                if (data.code == 100) {
                    $("#p_totalfav").html(parseInt($("#p_totalfav").html()) + 1);
                    $("#a_favdone").hide();
                    $("#a_favfinish").show();
                } else if (data.code == 101) {
                    $("#p_totalfav").html(parseInt($("#p_totalfav").html()) - 1);
                    $("#a_favdone").show();
                    $("#a_favfinish").hide();
                }
            } else if (data.code < 0) {
                if (data.code == -102) {
                    user_modellogin.showLoginDialog('');
                }
            }
        }
    }).always(function() {
        if ($("#a_favdone").val() != undefined) {
            $("#a_favdone").text("收藏本书");
            $("#a_favdone").attr("href", "javascript:doFavorite(" + bid + ")");
            $("#spanCancelFav").text("取消收藏");
            $("#spanCancelFav").attr("disabled", false);
        }
    });
}
function dofav(bid) {
    var code = 0;
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'dofavorite',
            bid: bid
        },
        success: function(data) {
            code = data.code;
        }
    });
    return code;
}
function showShare(needctrl) {
    if (needctrl == 1) {
        var top = $("#a_share").position().top;
        var left = $("#a_share").position().left;
        $("#divShare").css("left", (left - 24)).css("top", (top + 38));
    }
    if ($("#divShare").css("display") == "none") {
        $("#divShare").fadeIn(fadeinTime);
    } else {
        $("#divShare").fadeOut(fadeoutTime);
    }
    $("body").click(function() {
        if ($("#divShare").css("display") == "block") {
            $("#divShare").fadeOut(fadeoutTime);
        }
    });
}
function showFlower(bid) {
    fcurselect = 1;
    $("#txtFlower").val(1);
    $("#divflower .selected").removeClass("selected");
    $($("#divflower a")[0]).addClass("selected");
    $("#txtFComment").val("");
    if ($(".bodybg").css("display") == "none") {
        $(".bodybg").fadeIn(fadeinTime,
        function() {
            $(".bodybg").click(function() {
                closeFlower(0);
            });
            $("#flowermodal").css("position", "fixed").css("top", "135px").css("z-index", "1001").css("left", "50%").css("margin-left", "-235px");
            $("#flowermodal").fadeIn(fadeinTime);
            $("#txtFlower").focus();
        });
    } else {
        $(".bodybg").click(function() {
            closeFlower(0);
        });
        $("#flowermodal").css("position", "fixed").css("top", "135px").css("z-index", "1001").css("left", "50%").css("margin-left", "-235px");
        $("#flowermodal").fadeIn(fadeinTime);
        $("#txtFlower").focus();
    }
    if (window.userInfo == undefined) {
        $("#b_lastflower").text(0);
        $("#btnSendFlower").attr("disabled", "disabled");
        $("#btnSendFlower").addClass("inputbtndisable");
        $("#a_closeFlowerToLogin").show();
    } else {
        getLastFCount(bid);
        $("#btnSendFlower").attr("disabled", false);
        $("#btnSendFlower").removeClass("inputbtndisable");
        $("#a_closeFlowerToLogin").hide();
    }
}
function closeFlower(islogin) {
    $("#flowermodal").fadeOut(fadeoutTime,
    function() {
        if (islogin == 1) {
            user_modellogin.showLoginDialog(8);
        } else if (islogin == 2) {
            keytype = "login";
            user_modellogin.showLoginDialog(4);
        } else {
            $(".bodybg").fadeOut(fadeoutTime);
        }
    });
    if ($("#hidPageType").val() == "content") {
        $($("a[category='leftmenu']")[3]).removeClass("active");
    }
}
function showTicket(bid) {
    tcurselect = 1;
    $("#txtTicket").val(1);
    $("#divticket .selected").removeClass("selected");
    $($("#divticket a")[0]).addClass("selected");
    $("#txtTComment").val("");
    $(".bodybg").fadeIn(fadeinTime,
    function() {
        $(".bodybg").click(function() {
            closeTicket(0);
        });
        $("#ticketmodal").css("position", "fixed").css("top", "135px").css("z-index", "1001").css("left", "50%").css("margin-left", "-235px");
        $("#ticketmodal").fadeIn(fadeinTime);
        $("#txtTicket").focus();
    });
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'checkticketopen'
        },
        beforeSend: function() {},
        success: function(data) {
            if (data.result == "refuse") {
                $("#spanLastHsCoin").text("0");
                $("#spanSilver").text("0");
                $("#btnSendPro").addClass("inputbtndisable");
                $("#btnSendPro").attr("disabled", "disabled");
                $("#spanloginProTip").html("系统维护时间，红票投递通道暂时关闭，请您耐心等待。");
            } else if (data.result == "allow") {
                if (window.userInfo == undefined) {
                    $("#b_lastticket").text(0);
                    $("#btnSendTicket").attr("disabled", "disabled");
                    $("#btnSendTicket").addClass("inputbtndisable");
                    $("#a_closeTicketToLogin").show();
                } else {
                    getLastTCount(bid);
                    $("#btnSendTicket").attr("disabled", false);
                    $("#btnSendTicket").removeClass("inputbtndisable");
                    $("#a_closeTicketToLogin").hide();
                }
            }
        }
    }).always(function() {});
}
function closeTicket(islogin) {
    $("#ticketmodal").fadeOut(0,
    function() {
        if (islogin == 1) {
            user_modellogin.showLoginDialog(9);
        } else if (islogin == 2) {
            keytype = "login";
            user_modellogin.showLoginDialog(5);
        } else {
            $(".bodybg").fadeOut(fadeoutTime);
        }
    });
    if ($("#hidPageType").val() == "content") {
        $($("a[category='leftmenu']")[4]).removeClass("active");
    }
}
var fcurselect = 1;
function initFlower() {
    $("#txtFlower").val(fcurselect);
    $("#divflower .selected").removeClass("selected");
    $($("#divflower a")[0]).addClass("selected");
    var inputtemp = 0;
    $("#divflower a").mouseover(function() {
        inputtemp = 1;
        var num = $(this).attr("index");
        for (var i = fcurselect; i < num; i++) {
            $($("#divflower a")[i]).addClass("selected");
        }
        for (var i = $("#divflower .selected").length; i > $(this).attr("index"); i--) {
            if ($(this).attr("index") >= fcurselect) {
                $($("#divflower a")[i - 1]).removeClass("selected");
            }
        }
    });
    $("#divflower a").mouseout(function() {
        inputtemp = 0;
        setTimeout(function() {
            if (inputtemp == 0) {
                var seltotal = $("#divflower .selected").length;
                for (var i = fcurselect; i < seltotal; i++) {
                    $($('#divflower a')[i]).removeClass('selected');
                }
            }
        },
        300);
    });
    $("#txtFlower").numeral();
    $("#divflower a").click(function() {
        fcurselect = $(this).attr("index");
        $("#txtFlower").val(fcurselect);
        var seltotal = $("#divflower .selected").length;
        for (var i = fcurselect; i < seltotal; i++) {
            $($('#divflower a')[i]).removeClass('selected');
        }
        $("#txtFlower").focus();
    });
    $("#btnFlowerUp").click(function() {
        fcurselect = $("#txtFlower").val();
        max_flowers = $("#b_lastflower").text();
        if (parseInt(fcurselect) >= parseInt(max_flowers)) {
            $("#txtFlower").val(max_flowers);
            return;
        }
        if (parseInt(fcurselect) < 5) {
            $("#divflower a[index='" + (parseInt(fcurselect) + 1) + "']").mouseover();
            $("#divflower a[index='" + (parseInt(fcurselect) + 1) + "']").click();
        } else {
            fcurselect++;
            $("#txtFlower").val(fcurselect);
        }
        $("#txtFlower").focus();
    });
    $("#btnFlowerDown").click(function() {
        fcurselect = $("#txtFlower").val();
        if (fcurselect - 1 <= 0) {
            return;
        }
        if (parseInt(fcurselect) <= 5) {
            $("#divflower a[index='" + (parseInt(fcurselect) - 1) + "']").click();
        } else {
            fcurselect--;
            $("#txtFlower").val(fcurselect);
        }
        $("#txtFlower").focus();
    });
    $("#txtFlower").keyup(function(event) {
        switch (event.keyCode) {
        case 13:
            fcurselect = $("#txtFlower").val();
            if (fcurselect <= 5) {
                $("#divflower a").removeClass('selected');
                for (var i = 1; i <= fcurselect; i++) {
                    $("#divflower a[index=" + i + "]").addClass('selected');
                }
            }
            break;
        case 38:
            $("#btnFlowerUp").click();
            break;
        case 40:
            $("#btnFlowerDown").click();
            break;
        case 39:
            $("#btnFlowerUp").click();
            break;
        case 37:
            $("#btnFlowerDown").click();
            break;
        }
    });
}
function getLastFCount(bid) {
    $.ajax({
        url:
        hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: true,
        data: {
            method: 'getlastfcount',
            bid: bid
        },
        beforeSend: function() {},
        success: function(data) {
            $("#b_lastflower").text(data.msg);
            if (data.msg <= 0 || data.code == -102) {
                $("#b_lastflower").text(0);
                $("#btnSendFlower").attr("disabled", "disabled");
                $("#btnSendFlower").addClass('inputbtndisable');
            } else {
                $("#btnSendFlower").attr("disabled", false);
                $("#btnSendFlower").removeClass('inputbtndisable');
            }
        }
    });
}
function getLastTCount(bid) {
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: true,
        data: {
            method: 'getlasttcount',
            bid: bid
        },
        beforeSend: function() {},
        success: function(data) {
            $("#b_lastticket").text(data.msg);
            if (data.msg <= 0 || data.code == -102) {
                $("#b_lastticket").text(0);
                $("#btnSendTicket").attr("disabled", "disabled");
                $("#btnSendTicket").addClass('inputbtndisable');
            } else {
                $("#btnSendTicket").attr("disabled", false);
                $("#btnSendTicket").removeClass('inputbtndisable');
            }
        }
    });
}
var tcurselect = 1;
function initTicket() {
    $("#txtTicket").val(tcurselect);
    $("#divticket .selected").removeClass("selected");
    $($("#divticket a")[0]).addClass("selected");
    var inputtemp = 0;
    $("#divticket a").mouseover(function() {
        inputtemp = 1;
        var num = $(this).attr("index");
        for (var i = tcurselect; i < num; i++) {
            $($("#divticket a")[i]).addClass("selected");
        }
        for (var i = $("#divticket .selected").length; i > $(this).attr("index"); i--) {
            if ($(this).attr("index") >= tcurselect) {
                $($("#divticket a")[i - 1]).removeClass("selected");
            }
        }
    });
    $("#divticket a").mouseout(function() {
        inputtemp = 0;
        setTimeout(function() {
            if (inputtemp == 0) {
                var seltotal = $("#divticket .selected").length;
                for (var i = tcurselect; i < seltotal; i++) {
                    $($('#divticket a')[i]).removeClass('selected');
                }
            }
        },
        300);
    });
    $("#txtTicket").numeral();
    $("#divticket a").click(function() {
        tcurselect = $(this).attr("index");
        $("#txtTicket").val(tcurselect);
        var seltotal = $("#divticket .selected").length;
        for (var i = tcurselect; i < seltotal; i++) {
            $($('#divticket a')[i]).removeClass('selected');
        }
        $("#txtTicket").focus();
    });
    $("#btnTicketUp").click(function() {
        tcurselect = $("#txtTicket").val();
        max_ticket = $("#b_lastticket").text();
        if (parseInt(tcurselect) >= parseInt(max_ticket)) {
            $("#txtTicket").val(max_ticket);
            return;
        }
        if (parseInt(tcurselect) < 5) {
            $("#divticket a[index='" + (parseInt(tcurselect) + 1) + "']").mouseover();
            $("#divticket a[index='" + (parseInt(tcurselect) + 1) + "']").click();
        } else {
            tcurselect++;
            $("#txtTicket").val(tcurselect);
        }
        $("#txtTicket").focus();
    });
    $("#btnTicketDown").click(function() {
        tcurselect = $("#txtTicket").val();
        if (tcurselect - 1 <= 0) {
            return;
        }
        if (parseInt(tcurselect) <= 5) {
            $("#divticket a[index='" + (parseInt(tcurselect) - 1) + "']").click();
        } else {
            tcurselect--;
            $("#txtTicket").val(tcurselect);
        }
        $("#txtTicket").focus();
    });
    $("#txtTicket").keyup(function(event) {
        switch (event.keyCode) {
        case 13:
            tcurselect = $("#txtTicket").val();
            if (tcurselect <= 5) {
                $("#divticket a").removeClass('selected');
                for (var i = 1; i <= tcurselect; i++) {
                    $("#divticket a[index=" + i + "]").addClass('selected');
                }
            }
            break;
        case 38:
            $("#btnTicketUp").click();
            break;
        case 40:
            $("#btnTicketDown").click();
            break;
        case 39:
            $("#btnTicketUp").click();
            break;
        case 37:
            $("#btnTicketDown").click();
            break;
        }
    });
}
function sendFlower(bid) {
    hideFace();
    var num = $.trim($("#txtFlower").val());
    if (isNaN(num)) {
        return;
    }
    if (parseInt(num) > parseInt($("#b_lastflower").text())) {
        closeFlower(0);
        jalert("通知", "您要赠送的鲜花数量已超过上限。", null);
        return;
    }
    var comment = $.trim($("#txtFComment").val());
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'sendflower',
            bid: bid,
            num: num,
            content: comment
        },
        beforeSend: function() {
            $("#btnSendFlower").attr("disabled", "disabled");
        },
        success: function(data) {
            if ($("#hidPageType").val() == "bookindex") {
                closeFlower(0);
            } else if ($("#hidPageType").val() == "content") {
                if ($(".bodybg").css("display") == "block") {
                    $(".bodybg").fadeOut(fadeoutTime);
                }
                $($("a[category='leftmenu']")[3]).removeClass("active");
                if ($("#flowermodal").css("display") == 'block') {
                    keytype = "setflower";
                    $("#flowermodal").fadeOut(fadeoutTime);
                }
            }
            if (data.code == -102) {
                jalert("通知", data.msg,
                function() {
                    goToLogin($("#hidsign").val());
                });
            } else if (data.code == 103) {
                jalert("通知", data.msg,
                function() {});
            } else if (data.code == -107) {
                jalert("通知", data.msg, null);
            } else if (data.code == -109) {
                jalert("通知", data.msg, null);
            }
        }
    }).always(function() {
        $("#btnSendFlower").attr("disabled", false);
    });
}
function sendTicket(bid) {
    hideFace();
    var num = $.trim($("#txtTicket").val());
    if (isNaN(num)) {
        return;
    }
    if (parseInt(num) > parseInt($("#b_lastticket").text())) {
        closeTicket(0);
        jalert("通知", "您要投递的投红票数量已超过上限。", null);
        return;
    }
    var comment = $.trim($("#txtTComment").val());
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'sendticket',
            bid: bid,
            num: num,
            content: comment
        },
        beforeSend: function() {
            $("#btnSendTicket").attr("disabled", "disabled");
        },
        success: function(data) {
            if ($("#hidPageType").val() == "bookindex" || $("#hidPageType").val() == "fansrank") {
                closeTicket(0);
            } else if ($("#hidPageType").val() == "content") {
                if ($(".bodybg").css("display") == "block") {
                    $(".bodybg").fadeOut(fadeoutTime);
                }
                $($("a[category='leftmenu']")[4]).removeClass("active");
                if ($("#ticketmodal").css("display") == 'block') {
                    keytype = "page";
                    $("#ticketmodal").fadeOut(fadeoutTime);
                }
            }
            if (data.code == -102) {
                jalert("通知", data.msg,
                function() {
                    goToLogin($("#hidsign").val());
                });
            } else if (data.code == 104) {
                jalert("通知", "投递成功！提示：每部作品您每月最多可投5票，每日最多可投2票，系统会在投票后的 2 小时内显示出增加的红票数量，请请耐心等待。",
                function() {});
            } else if (data.code == -108) {
                jalert("通知", data.msg, null);
            } else if (data.code == -110) {
                jalert("通知", data.msg, null);
            } else if (data.code == -153) {
                jalert("通知", "现在是系统维护时间，红票投递通道暂时关闭，请您耐心等待。", null);
            }
        }
    }).always(function() {
        $("#btnSendTicket").attr("disabled", false);
    });
}
function checkLogin() {
    var code = -102;
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'checklogin'
        },
        beforeSend: function() {},
        success: function(data) {
            if (data.code == -102) {
                code = data.code;
                user_modellogin.showLoginDialog("");
            } else {
                code = 102;
            }
        }
    });
    return code;
}
function initTrendScroll() {
    if ($("#divbooktrend").html() != undefined) {
        $("#divbooktrend").doScroll({
            speed: 40,
            rowHeight: 59
        });
    }
}
var curproindex = 0;
function initProperties() {
    if ($("li[category='selectproperties']").length > 0) {
        if ($("#hidPageType").val() == "bookindex" || $("#hidPageType").val() == "content" || $("#hidPageType").val() == "fansrank") {
            $("#txtPCount").numeral();
            if ($("#hidPageType").val() == "bookindex") {
                $("li[category='selectproperties']").click(function() {
                    if ($(this).attr("index") == curproindex) {
                        $("#divProperties").fadeOut(fadeoutTime);
                        curproindex = 0;
                    } else {
                        curproindex = $(this).attr("index");
                        $("li[category='selectproperties']").removeClass("select");
                        $("li[category='selectproperties']").attr("select", "0");
                        $(this).addClass("select");
                        $(this).attr("select", "1");
                        $("#divProperties").fadeIn(fadeinTime);
                        $("#spanHsCoin").text($(this).attr("price"));
                        $("#spanPcount").text($(this).attr("name"));
                        $("#txtPComment").attr("placeholder", "赏" + $(this).attr("name") + "1" + $(this).attr("unit") + "，望再接再厉，争取更大胜利！");
                        $("#c_unit").text($(this).attr("unit"));
                        $("#txtPCount").val(1);
                        $("#txtPCount").focus();
                    }
                });
            } else if ($("#hidPageType").val() == "content" || $("#hidPageType").val() == "fansrank") {
                $("li[category='selectproperties']").click(function() {
                    $("li[category='selectproperties']").removeClass("select");
                    $("li[category='selectproperties']").attr("select", "0");
                    $(this).addClass("select");
                    $(this).attr("select", "1");
                    $("#divProperties").fadeIn(fadeinTime);
                    $("#spanHsCoin").text($(this).attr("price"));
                    $("#spanPcount").text($(this).attr("name"));
                    $("#txtPComment").attr("placeholder", "赏" + $(this).attr("name") + "1" + $(this).attr("unit") + "，望再接再厉，争取更大胜利！");
                    $("#c_unit").text($(this).attr("unit"));
                    $("#txtPCount").val(1);
                    $("#txtPCount").focus();
                });
            }
            $("#txtPCount").keyup(function(event) {
                switch (event.keyCode) {
                case 13:
                    var price = $("li[select='1']").attr("price");
                    $("#spanHsCoin").text(parseInt(price) * parseInt($("#txtPCount").val()));
                    break;
                case 38:
                    addPCount();
                    break;
                case 40:
                    reducePCount();
                    break;
                case 39:
                    addPCount();
                    break;
                case 37:
                    reducePCount();
                    break;
                }
            });
            $("#txtPComment").val("");
            if (window.userInfo != undefined) {
                $("#spanLastHsCoin").text(window.userInfo.money);
                $("#spanSilver").text(window.userInfo.egold);
                $("#btnSendPro").removeClass("inputbtndisable");
                $("#btnSendPro").attr("disabled", false);
                $("#spanloginProTip").text("");
            } else {
                $("#spanLastHsCoin").text("0");
                $("#spanSilver").text("0");
                $("#btnSendPro").addClass("inputbtndisable");
                $("#btnSendPro").attr("disabled", "disabled");
                if ($("#hidPageType").val() == "content" || $("#hidPageType").val() == "fansrank") {
                    $("#spanloginProTip").html("登录后才可以赠送，您可以点击<a style='color:red' href='javascript:void(0)' onclick='closeZanshang(1)'>此处</a>登录");
                } else if ($("#hidPageType").val() == "bookindex") {
                    $("#spanloginProTip").html("登录后才可以赠送，您可以点击<a style='color:red' href='javascript:void(0)' onclick='user_modellogin.showLoginDialog(\"10\")'>此处</a>登录");
                }
            }
        }
    }
}
function sendPro(bid) {
    hideFace();
    if ($("#hidPageType").val() == "content" || $("#hidPageType").val() == "fansrank") {
        closeZanshang(0);
    }
    var pid = $("li[select='1']").attr("pid");
    var num = $.trim($("#txtPCount").val());
    var comment = $.trim($("#txtPComment").val());
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'sendpro',
            bid: bid,
            num: num,
            pid: pid,
            sexflag: $("#hidsign").val(),
            content: comment
        },
        beforeSend: function() {
            $("#btnSendPro").attr("disabled", "disabled");
        },
        success: function(data) {
            if ($("#hidPageType").val() == "fansrank" || $("#hidPageType").val() == "content") {
                if ($(".bodybg").css("display") == "block") {
                    $(".bodybg").fadeOut(fadeoutTime,
                    function() {
                        $("#divShang").fadeOut(fadeoutTime);
                    });
                } else {
                    $("#divShang").fadeOut(fadeoutTime);
                }
            }
            if (data.code == -102) {
                jalert("通知", data.msg,
                function() {
                    goToLogin($("#hidsign").val());
                });
            } else if (data.code == 106) {
                $("#spanOnePCount" + pid).text(parseInt($("#spanOnePCount" + pid).text()) + parseInt(data.num));
                $("#a_Pcount").text(parseInt($("#a_Pcount").text()) + parseInt(data.num));
                if (data.moneyinfo.deductegold > 0) {
                    $("#spanSilver").text(parseInt($("#spanSilver").text()) - data.moneyinfo.deductegold);
                }
                if (data.moneyinfo.deductmoney > 0) {
                    $("#spanLastHsCoin").text(parseInt($("#spanLastHsCoin").text()) - data.moneyinfo.deductmoney);
                }
                jalert("通知", "赠送成功！本次共消费 " + (data.moneyinfo.deductegold != 0 ? data.moneyinfo.deductegold + "红薯银币": "") + (data.moneyinfo.deductmoney != 0 ? data.moneyinfo.deductmoney + "红薯币": "") + "。感谢您的支持！",
                function() {
                    window.userInfo.money = data.moneyinfo.lastmoney;
                    window.userInfo.egold = data.moneyinfo.lastegold;
                    if ($("#hidPageType").val() == "bookindex") {
                        $.ajax({
                            url: hs_const_url.bookajax,
                            type: 'post',
                            dataType: 'json',
                            async: false,
                            data: {
                                method: 'getbookpro',
                                bid: bid,
                                type: 1,
                                limit: 3
                            },
                            success: function(data) {
                                if (data.code == 139) {
                                    $("#ul_proListTime").html("");
                                    var html = "";
                                    for (var i = 0; i < data.list.length; i++) {
                                        html += '<li><div class="photo"><a href="' + hs_const_domain.homeHost + '/userspace/u/' + data.list[i]['uid'] + '/index.html" target="_blank"><img src="' + getUserFacePath(data.list[i]['uid'], "middle") + '" /></a></div><div class="name"><a href="' + hs_const_domain.homeHost + '/userspace/u/' + data.list[i]['uid'] + '/index.html" target="_blank">' + data.list[i]['nickname'] + '</a></div><div class="prop"><img src="' + hs_const_domain.resourceHost + "/Public/images" + data.list[i]['imgurl'] + '" /></div><div class="prop-num">X' + data.list[i]['num'] + '</div></li>';
                                    }
                                    $("#ul_proListTime").html(html);
                                }
                            }
                        });
                        $.ajax({
                            url: hs_const_url.bookajax,
                            type: 'post',
                            dataType: 'json',
                            async: false,
                            data: {
                                method: 'getbookpro',
                                bid: bid,
                                type: 2,
                                limit: 3
                            },
                            success: function(data) {
                                if (data.code == 139) {
                                    $("#ul_proListPrice").html("");
                                    var html = "";
                                    for (var i = 0; i < data.list.length; i++) {
                                        html += '<li><div class="photo"><a href="' + hs_const_domain.homeHost + '/userspace/u/' + data.list[i]['uid'] + '/index.html" target="_blank"><img src="' + getUserFacePath(data.list[i]['uid'], "middle") + '" /></a></div><div class="name"><a href="' + hs_const_domain.homeHost + '/userspace/u/' + data.list[i]['uid'] + '/index.html" target="_blank">' + data.list[i]['nickname'] + '</a></div><div class="prop"><img src="' + hs_const_domain.resourceHost + "/Public/images" + data.list[i]['imgurl'] + '" /></div><div class="prop-num">X' + data.list[i]['num'] + '</div></li>';
                                    }
                                    $("#ul_proListPrice").html(html);
                                }
                            }
                        });
                    }
                });
            } else if (data.code == -111) {
                jalert("通知", data.msg, null);
            } else if (data.code == -112) {
                jalert("通知", data.msg, null);
            } else if (data.code == -113) {
                jalert("通知", "余额不足，请充值。", null);
            } else if (data.code == -114) {
                jalert("通知", data.msg, null);
            }
        }
    }).always(function() {
        $("#btnSendPro").attr("disabled", false);
        $("#dialog-confirm").html('<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>确认此操作吗？');
    });
    if ($("#hidPageType").val() == "content") {
        var topspace = (parseInt($("#contitletop").offset().top) - 3);
        $("div[role='dialog']").css("top", (window.screen.height / 2) - 90);
        $("html,body").animate({
            scrollTop: topspace
        },
        0);
    }
}
function reducePCount() {
    if (parseInt($("#txtPCount").val()) > 1) {
        $("#txtPCount").val(parseInt($("#txtPCount").val()) - 1);
        var price = $("li[select='1']").attr("price");
        $("#spanHsCoin").text(parseInt(price) * parseInt($("#txtPCount").val()));
        $("#txtPComment").attr("placeholder", "赏" + $("li[select='1']").attr("name") + parseInt($("#txtPCount").val()) + "个，望再接再厉，争取更大胜利！");
    }
    $("#txtPCount").focus();
}
function addPCount() {
    $("#txtPCount").val(parseInt($("#txtPCount").val()) + 1);
    var price = $("li[select='1']").attr("price");
    $("#spanHsCoin").text(parseInt(price) * parseInt($("#txtPCount").val()));
    $("#txtPComment").attr("placeholder", "赏" + $("li[select='1']").attr("name") + parseInt($("#txtPCount").val()) + "个，望再接再厉，争取更大胜利！");
    $("#txtPCount").focus();
}
function addZan(commentid, sign) {
    hideFace();
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'addzan',
            commentid: commentid
        },
        beforeSend: function() {},
        success: function(data) {
            if (data.code == -102) {
                jalert("通知", data.msg,
                function() {
                    goToLogin($("#hidsign").val());
                });
            } else if (data.code == -115) {
                jalert("通知", data.msg, null);
            } else if (data.code == 108) {
                $("#zancount" + commentid + sign).text(parseInt($("#zancount" + commentid + sign).text()) + 1);
            }
        }
    }).always(function() {});
}
function initCommentChange() {
    $("div[category='comment'] h5").on("click",
    function() {
        hideFace();
        $("div[category='comment'] h5").removeClass("active");
        $(this).addClass("active");
        $("ul[category='commentlist']").hide();
        $("ul[category='commentlist'][index='" + $(this).attr("index") + "']").show();
        if ($(this).attr("index") == "3") {
            $("#divChoiceChapter").show();
        } else {
            $("#divChoiceChapter").hide();
        }
        if ($("div[category='npageList']").length > 0) {
            $("div[category='npageList']").hide();
            $("div[category='npageList'][index='" + $(this).attr("index") + "']").show();
        }
    });
    $("#chbLComment").click(function() {
        hideFace();
        changeMaxWords();
        if ($("#chbLComment").prop("checked") == true) {
            $("#txtLtitle").show();
        } else {
            $("#txtLtitle").hide();
        }
    });
}
function insertBookName() {
    hideFace();
    insertText("txtBookComment", "《请输入书名》");
    var begin = $('#txtBookComment').val().lastIndexOf("《") + 1;
    var end = $('#txtBookComment').val().lastIndexOf("》");
    textSelect(document.getElementById("txtBookComment"), begin, end);
}
function initWordCount() {
    try {
        changeMaxWords();
        var txt = $("#txtBookComment").val();
        var counter = txt.length;
        $("#curWords").text(counter);
        $(document).keyup(function() {
            changeMaxWords();
            var txt = $("#txtBookComment").val();
            var counter = txt.length;
            $("#curWords").text(counter);
            if (counter >= parseInt($("#totalWords").text())) {
                $("#txtBookComment").val(txt.substring(0, total));
            }
        });
    } catch(e) {}
}
function initBookComment() {
    if ($("#txtBookComment").val() != undefined) {
        $("img[category='commentface']").click(function() {
            insertText("txtBookComment", "[em:" + $(this).attr("index") + ":]");
        });
    }
}
function changeMaxWords() {
    if ($("#chbLComment").prop("checked") == true) {
        $("#totalWords").text(1000);
        $("#txtBookComment").attr("maxlength", 1000);
    } else {
        var txt = $("#txtBookComment").val();
        var counter = txt.length;
        if (counter > 300) {
            $("#txtBookComment").val(txt.substring(0, 300));
            $("#curWords").text(300);
        }
        $("#totalWords").text(300);
        $("#txtBookComment").attr("maxlength", 300);
    }
}
function showCommentFace() {
    if ($("#comment_faces").css("display") == "none") {
        var top = $("#a_face").position().top;
        var left = $("#a_face").position().left;
        $("#comment_faces").css("position", "absolute").css("top", top + 20).css("left", left - 8);
        $("#comment_faces").show();
    } else {
        $("#comment_faces").hide();
    }
    $("body").click(function() {
        if ($("#comment_faces").css("display") == "block") {
            $("#comment_faces").hide();
        }
    });
}
function sendComment(bid) {
    hideFace();
    var title = "";
    if ($("#txtLtitle").val() != undefined) {
        title = $.trim($("#txtLtitle").val());
    }
    var content = $.trim($("#txtBookComment").val());
    if (content.length == 0) {
        $('#txtBookComment').css('background-color', 'rgb(255, 238, 238)');
        setTimeout("$('#txtBookComment').css('background-color', '');", 800);
        return;
    }
    var lcomment = 0;
    if ($("#chbLComment").prop("checked") == true) {
        lcomment = 1;
    }
    var chapterid = 0;
    if ($("#txtChapterid").val() != undefined) {
        chapterid = $("#txtChapterid").val();
    }
    var chaptername = '';
    if (chapterid != 0) {
        chaptername = $("#selChapterid").find("option:selected").text();;
    }
    var reg = new RegExp("\n", "g");
    content = content.replace(reg, "<br/>");
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'addcomment',
            bid: bid,
            title: title,
            content: encodeURIComponent(content),
            lcomment: lcomment,
            chapterid: chapterid,
            chaptername: chaptername
        },
        beforeSend: function() {
            $("#btnSendComment").attr("disabled", "disabled");
        },
        success: function(data) {
            if ($("#hidPageType").val() == "content") {
                $("a[category='leftmenu'][index='5']").removeClass('active');
                $("#divCommentOpen").fadeOut(fadeoutTime);
            }
            if (data.code == -102) {
                jalert("通知", data.msg,
                function() {
                    goToLogin($("#hidsign").val());
                });
            } else if (data.code == -118) {
                jalert("通知", data.msg, null);
            } else if (data.code == 'kill') {
                jalert("通知", data.msg, null);
            } else if (data.code == 109) {
                jalert("通知", data.msg,
                function() {
                    if ($("#hidPageType").val() == "content") {
                        keytype = "page";
                    } else {
                        location = hs_const_domain.bookHost + "/comment/" + bid + "/index.do?npage=" + data.totalpage + "&pagesign=1#li_commentlist" + data.comment_id;
                    }
                });
                $("button[role='button']").hide();
                setTimeout(function() {
                    $("button[role='button']").click();
                },
                2000);
            }
        }
    }).always(function() {
        $("#btnSendComment").attr("disabled", false);
        $('#txtBookComment').val("");
    });
}
function sendCommentDetail(bid, chapterid, chaptername) {
    hideFace();
    var title = "";
    if ($("#txtLtitle").val() != undefined) {
        title = $.trim($("#txtLtitle").val());
    }
    var content = $.trim($("#txtBookComment").val());
    if (content.length == 0) {
        $('#txtBookComment').css('background-color', 'rgb(255, 238, 238)');
        setTimeout("$('#txtBookComment').css('background-color', '');", 800);
        return;
    }
    var lcomment = 0;
    if ($("#chbLComment").prop("checked") == true) {
        lcomment = 1;
    }
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'addcomment',
            bid: bid,
            title: title,
            content: content,
            lcomment: lcomment,
            chapterid: chapterid,
            chaptername: escape(chaptername)
        },
        beforeSend: function() {
            $("#btnSendComment").attr("disabled", "disabled");
        },
        success: function(data) {
            if ($("#hidPageType").val() == "content") {
                $("a[category='leftmenu'][index='5']").removeClass('active');
                $("#divCommentOpen").fadeOut(fadeoutTime);
            }
            if (data.code == -102) {
                jalert("通知", data.msg,
                function() {
                    goToLogin($("#hidsign").val());
                });
            } else if (data.code == -118) {
                jalert("通知", data.msg, null);
            } else if (data.code == 109) {
                jalert("通知", data.msg,
                function() {
                    keytype = "page";
                });
            }
        }
    }).always(function() {
        $("#btnSendComment").attr("disabled", false);
        $('#txtBookComment').val("");
    });
}
function initReply(commentid, category) {
    var total = 300;
    var txt = $("#txtReply" + commentid + category).val();
    var counter = txt.length;
    $("#replyWords" + commentid + category).text(counter);
    $(document).keyup(function() {
        var txt = $("#txtReply" + commentid + category).val();
        var counter = txt.length;
        $("#replyWords" + commentid + category).text(counter);
        if (counter >= total) {
            $("#txtReply" + commentid + category).val(txt.substring(0, total));
        }
    });
    $("img[category='replyface']").click(function() {
        insertText("txtReply" + curcommentid + curcategory, "[em:" + $(this).attr("index") + ":]");
    });
}
function getMoreReply(commentid, type) {
    hideFace();
    var curshow = $("ul[sign='" + type + "'] li[category='reply" + commentid + "']").length;
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'getreply',
            commentid: commentid,
            curshow: curshow
        },
        beforeSend: function() {},
        success: function(data) {
            if (data.code == -102) {
                jalert("通知", data.msg,
                function() {
                    goToLogin($("#hidsign").val());
                });
            } else if (data.code == -120) {
                jalert("通知", data.msg, null);
            } else if (data.code == 110) {
                for (var i = data.replylist.length - 1; i >= 0; i--) {
                    var cururl = "";
                    if (parseInt(data.replylist[i].uid) != 0) {
                        cururl = " href='/userspace/" + data.replylist[i].uid + "/0.html' title='" + (data.replylist[i].nickname == "" ? data.replylist[i].username: data.replylist[i].nickname) + "' target='_blank'";
                    } else {
                        cururl = " href='javascript:void(0)' ";
                    }
                    $($("ul[sign='" + type + "'] li[category='reply" + commentid + "']")[0]).before("<li category='reply" + data.replylist[i].comment_id + "' class='clearfix'><div class='right'><p class='author2'>" + " <a " + cururl + " class='" + ($("#hidsign").val() == "2" ? "cboy": "cgirl") + "'>" + (data.replylist[i].nickname == "" ? data.replylist[i].username: data.replylist[i].nickname) + "</a></p><p>" + data.replylist[i].content + "</p><div class='comxinxi  top10'><span class='c2'>" + getDateDiff(data.replylist[i].creation_date) + "</span></div></div></li>");
                }
                if (data.isend == 1) {
                    $("#divMoreReply" + commentid + type).hide();
                }
            }
        }
    }).always(function() {});
}
function insertReply(commentid, category) {
    hideFace();
    insertText("txtReply" + commentid + category, "《请输入书名》");
    var begin = $("#txtReply" + commentid + category).val().lastIndexOf("《") + 1;
    var end = $("#txtReply" + commentid + category).val().lastIndexOf("》");
    textSelect(document.getElementById("txtReply" + commentid + category), begin, end);
}
var curcommentid = 0;
var curcategory = '';
function showReplyFace(commentid, category) {
    var top = $("#a_replyface" + commentid + category).position().top;
    var left = $("#a_replyface" + commentid + category).position().left;
    if (curcommentid != commentid) {
        curcommentid = commentid;
        curcategory = category;
        $("#reply_faces").css("position", "absolute").css("top", top + 20).css("left", left - 8);
        $("#reply_faces").show();
    } else {
        $("#reply_faces").hide();
        curcommentid = 0;
        curcategory = '';
    }
    $("body").click(function() {
        if (curcommentid == commentid) {
            $("#reply_faces").hide();
            curcommentid = 0;
            curcategory = '';
        }
    });
}
function sendReply(commentid, bid, category) {
    hideFace();
    var content = $.trim($("#txtReply" + commentid + category).val());
    if (content.length == 0) {
        $("#txtReply" + commentid + category).css('background-color', 'rgb(255, 238, 238)');
        setTimeout("$('#txtReply" + commentid + category + "').css('background-color', '');", 800);
        return;
    }
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'addreply',
            commentid: commentid,
            bid: bid,
            content: content
        },
        beforeSend: function() {
            $("#btnSendReply" + commentid + category).attr("disabled", "disabled");
        },
        success: function(data) {
            if (data.code == -102) {
                user_modellogin.showLoginDialog();
            } else if (data.code == -121) {
                jalert("通知", data.msg, null);
            } else if (data.code == 111) {
                jalert("通知", data.msg,
                function() {
                    if (category == "") {
                        location = hs_const_domain.bookHost + "/commentdetail/" + commentid + ".do?page=" + data.totalpage;
                    } else {
                        getMorePageReply(data.totalpage, commentid, category);
                    }
                });
                $("#txtReply" + commentid + category).val("");
                $("button[role='button']").hide();
                setTimeout(function() {
                    $("button[role='button']").click();
                },
                2000);
            } else if (data.code == 'lock') {
                jalert("通知", data.msg, null);
            } else if (data.code == 'kill') {
                jalert("通知", data.msg, null);
            } else if (data.code < 0) {
                jalert('通知', data.msg, null);
            }
        }
    }).always(function() {
        $("#btnSendReply" + commentid + category).attr("disabled", false);
    });
}
function hideFace() {
    $("#comment_faces").css("position", "").css("top", 0).css("left", 0);
    $("#comment_faces").hide();
    $("#reply_faces").css("position", "").css("top", 0).css("left", 0);
    $("#reply_faces").hide();
    curcommentid = 0;
}
function changeNPage(page) {
    $("#txtnPage").val(page);
    npageform.submit();
}
function preNPage() {
    var page = parseInt($("#txtnPage").val());
    if (page > 1) {
        $("#txtnPage").val(page - 1);
        npageform.submit();
    }
}
function nextNPage(totalpage) {
    var page = parseInt($("#txtnPage").val());
    if (page >= totalpage) {
        return;
    }
    $("#txtnPage").val(page + 1);
    npageform.submit();
}
function changeJPage(page) {
    $("#txtjPage").val(page);
    jpageform.submit();
}
function preJPage() {
    var page = parseInt($("#txtjPage").val());
    if (page > 1) {
        $("#txtjPage").val(page - 1);
        jpageform.submit();
    }
}
function nextJPage(totalpage) {
    var page = parseInt($("#txtjPage").val());
    if (page + 1 >= totalpage) {
        return;
    }
    $("#txtjPage").val(page + 1);
    jpageform.submit();
}
function changeZPage(page) {
    $("#txtzPage").val(page);
    $("#txtChapterid").val($("#selChapterid").val());
    zpageform.submit();
}
function preZPage() {
    var page = parseInt($("#txtzPage").val());
    if (page > 1) {
        $("#txtzPage").val(page - 1);
        zpageform.submit();
    }
}
function nextZPage(totalpage) {
    var page = parseInt($("#txtzPage").val());
    if (page + 1 >= totalpage) {
        return;
    }
    $("#txtzPage").val(page + 1);
    zpageform.submit();
}
var uid = 0;
var clock;
var divFixPos = ["3px", "132px", "80px", "148px", "219px", "369px", "367px"];
function initContent() {
    if ($("#hidPageType").val() == "content") {
        book_chaptercontent.initBodyStatus();
        book_chaptercontent.defaultChapter();
        book_chaptercontent.initScrollBar();
        $("#txtFontSize").numeral();
        $("#txtFontSize").keyup(function(event) {
            switch (event.keyCode) {
            case 13:
                var curFontSize = parseFloat($("#divChpContent p").css("font-size"));
                var nowFontSize = parseFloat($("#txtFontSize").val());
                $("#txtFontSize").val(curFontSize);
                if (nowFontSize - curFontSize == 0) {
                    return;
                } else if (nowFontSize - curFontSize > 0) {
                    for (var i = 0; i < (nowFontSize - curFontSize); i++) {
                        addFontSize();
                    }
                } else if (nowFontSize - curFontSize < 0) {
                    for (var i = 0; i < (curFontSize - nowFontSize); i++) {
                        reduceFontSize();
                    }
                }
                break;
            case 39:
                if (keytype == "setopen") {
                    addFontSize();
                }
                break;
            case 37:
                if (keytype == "setopen") {
                    reduceFontSize();
                }
                break;
            case 38:
                if (keytype == "setopen") {
                    addFontSize();
                }
                break;
            case 40:
                if (keytype == "setopen") {
                    reduceFontSize();
                }
                break;
            }
        });
        $("#contitletop").click(function() {
            $("#divUserMenu").fadeOut(fadeoutTime);
            for (var i = 0; i < $("a[category='leftmenu']").length; i++) {
                if ($($("a[category='leftmenu']")[i]).hasClass("active")) {
                    if (i != 2) {
                        $($("a[category='leftmenu']")[i]).click();
                    }
                }
            }
        });
        $($("a[category='leftmenu']")[0]).click(function() {
            hideFace();
            for (var i = 0; i < $("div[category='leftmenudiv']").length; i++) {
                if (i != 0) {
                    $($("div[category='leftmenudiv']")[i]).hide();
                }
            }
            for (var i = 0; i < $("a[category='leftmenu']").length; i++) {
                if (i != 0) {
                    if ($($("a[category='leftmenu']")[i]).hasClass('active') == true) {
                        $($("a[category='leftmenu']")[i]).removeClass("active");
                    }
                }
            }
            if (parseInt($("#hidIsFav").val()) == 1) {
                $("a[category='leftmenu'][index='2']").addClass("active");
            }
            if ($(this).hasClass('active') == false) {
                $(this).addClass("active");
            } else {
                $(this).removeClass("active");
            }
            if ($("#divleftMenu").css("position") == "fixed") {
                $($("div[category='leftmenudiv']")[0]).css("position", "fixed").css("top", divFixPos[0]);
            }
            $($("div[category='leftmenudiv']")[0]).fadeToggle(fadetoggleTime,
            function() {
                var container = $($("div[category='leftmenudiv']")[0]);
                var scrollTo = $("div[data-type='chplist'][data-cid='" + book_chaptercontent.curcid + "']");
            });
        });
        $($("a[category='leftmenu']")[1]).click(function() {
            location = hs_const_domain.bookHost + "/book/" + book_chaptercontent.curbid + ".html";
        });
        initIsFav();
        $($("a[category='leftmenu']")[2]).click(function() {
            hideFace();
            if ($("#hidIsFav").val() != 0) {
                if (window.userInfo != undefined) {
                    inputBookshelf();
                    $($("a[category='leftmenu']")[2]).removeClass("active");
                    keytype = "page";
                    return;
                } else {
                    keytype = "login";
                    $($("a[category='leftmenu']")[2]).removeClass("active");
                    user_modellogin.showLoginDialog(3);
                }
            }
            for (var i = 0; i < $("div[category='leftmenudiv']").length; i++) {
                if (i != 1) {
                    $($("div[category='leftmenudiv']")[i]).hide();
                }
            }
            for (var i = 0; i < $("a[category='leftmenu']").length; i++) {
                if (i != 2) {
                    if ($($("a[category='leftmenu']")[i]).hasClass('active') == true) {
                        $($("a[category='leftmenu']")[i]).removeClass("active");
                    }
                }
            }
            if (parseInt($("#hidIsFav").val()) == 1) {
                $("a[category='leftmenu'][index='2']").addClass("active");
            }
            if (window.userInfo != undefined) {
                if ($($("a[category='leftmenu']")[2]).hasClass('active') == false) {
                    $($("a[category='leftmenu']")[2]).addClass("active");
                    $($("div[category='leftmenudiv']")[1]).fadeIn(fadeinTime,
                    function() {
                        if ($($("div[category='leftmenudiv']")[1]).css("display") == 'block') {
                            keytype = "dofav";
                        } else if ($($("div[category='leftmenudiv']")[1]).css("display") == 'none') {
                            keytype = "page";
                        }
                    });
                } else {
                    $($("a[category='leftmenu']")[2]).removeClass("active");
                    $($("div[category='leftmenudiv']")[1]).fadeOut(fadeoutTime,
                    function() {
                        if ($($("div[category='leftmenudiv']")[1]).css("display") == 'block') {
                            keytype = "dofav";
                        } else if ($($("div[category='leftmenudiv']")[1]).css("display") == 'none') {
                            keytype = "page";
                        }
                    });
                }
                if ($("#divleftMenu").css("position") == "fixed") {
                    $($("div[category='leftmenudiv']")[1]).css("position", "fixed").css("top", divFixPos[1]);
                }
            } else {
                keytype = "login";
                $($("a[category='leftmenu']")[2]).removeClass("active");
                user_modellogin.showLoginDialog(3);
            }
        });
        $($("a[category='leftmenu']")[3]).click(function() {
            hideFace();
            for (var i = 0; i < $("div[category='leftmenudiv']").length; i++) {
                if (i != 2) {
                    $($("div[category='leftmenudiv']")[i]).hide();
                }
            }
            for (var i = 0; i < $("a[category='leftmenu']").length; i++) {
                if (i != 3) {
                    if ($($("a[category='leftmenu']")[i]).hasClass('active') == true) {
                        $($("a[category='leftmenu']")[i]).removeClass("active");
                    }
                }
            }
            if (parseInt($("#hidIsFav").val()) == 1) {
                $("a[category='leftmenu'][index='2']").addClass("active");
            }
            if ($($("a[category='leftmenu']")[3]).hasClass('active') == false) {
                $($("a[category='leftmenu']")[3]).addClass("active");
                $("#flowermodal").fadeIn(fadeinTime,
                function() {
                    if ($("#flowermodal").css("display") == 'block') {
                        keytype = "setflower";
                    } else if ($("#flowermodal").css("display") == 'none') {
                        keytype = "page";
                    }
                    $("#txtFlower").focus();
                });
            } else {
                $($("a[category='leftmenu']")[3]).removeClass("active");
                $("#flowermodal").fadeOut(fadeoutTime,
                function() {
                    if ($("#flowermodal").css("display") == 'block') {
                        keytype = "setflower";
                    } else if ($("#flowermodal").css("display") == 'none') {
                        keytype = "page";
                    }
                });
            }
            if ($("#divleftMenu").css("position") == "fixed") {
                $("#flowermodal").css("position", "fixed").css("top", divFixPos[2]);
            }
            if (window.userInfo == undefined) {
                $("#b_lastflower").text(0);
                $("#btnSendFlower").attr("disabled", "disabled");
                $("#btnSendFlower").addClass("inputbtndisable");
                $("#a_closeFlowerToLogin").show();
            } else {
                getLastFCount(book_chaptercontent.curbid);
                $("#btnSendFlower").attr("disabled", false);
                $("#btnSendFlower").removeClass("inputbtndisable");
                $("#a_closeFlowerToLogin").hide();
            }
        });
        $($("a[category='leftmenu']")[4]).click(function() {
            if (book_chaptercontent.shouquaninfo >= 8) {
                hideFace();
                for (var i = 0; i < $("div[category='leftmenudiv']").length; i++) {
                    if (i != 3) {
                        $($("div[category='leftmenudiv']")[i]).hide();
                    }
                }
                for (var i = 0; i < $("a[category='leftmenu']").length; i++) {
                    if (i != 4) {
                        if ($($("a[category='leftmenu']")[i]).hasClass('active') == true) {
                            $($("a[category='leftmenu']")[i]).removeClass("active");
                        }
                    }
                }
                if (parseInt($("#hidIsFav").val()) == 1) {
                    $("a[category='leftmenu'][index='2']").addClass("active");
                }
                if ($($("a[category='leftmenu']")[4]).hasClass('active') == false) {
                    $($("a[category='leftmenu']")[4]).addClass("active");
                    $("#ticketmodal").fadeIn(fadeinTime,
                    function() {
                        if ($("#ticketmodal").css("display") == 'block') {
                            keytype = "setticket";
                        } else if ($("#ticketmodal").css("display") == 'none') {
                            keytype = "page";
                        }
                        $("#txtTicket").focus();
                    });
                } else {
                    $($("a[category='leftmenu']")[4]).removeClass("active");
                    $("#ticketmodal").fadeOut(fadeoutTime,
                    function() {
                        if ($("#ticketmodal").css("display") == 'block') {
                            keytype = "setticket";
                        } else if ($("#ticketmodal").css("display") == 'none') {
                            keytype = "page";
                        }
                    });
                }
                if ($("#divleftMenu").css("position") == "fixed") {
                    $("#ticketmodal").css("position", "fixed").css("top", divFixPos[3]);
                }
                $.ajax({
                    url: hs_const_url.bookajax,
                    type: 'post',
                    dataType: 'json',
                    async: false,
                    data: {
                        method: 'checkticketopen'
                    },
                    beforeSend: function() {},
                    success: function(data) {
                        if (data.result == "refuse") {
                            $("#spanLastHsCoin").text("0");
                            $("#spanSilver").text("0");
                            $("#btnSendPro").addClass("inputbtndisable");
                            $("#btnSendPro").attr("disabled", "disabled");
                            $("#spanloginProTip").html("<c style='color:red'>现在是系统维护时间，红票投递通道暂时关闭，请您耐心等待。</a>");
                        } else if (data.result == "allow") {
                            if (window.userInfo == undefined) {
                                $("#b_lastticket").text(0);
                                $("#btnSendTicket").attr("disabled", "disabled");
                                $("#btnSendTicket").addClass("inputbtndisable");
                                $("#a_closeTicketToLogin").show();
                            } else {
                                getLastTCount(book_chaptercontent.curbid);
                                $("#btnSendTicket").attr("disabled", false);
                                $("#btnSendTicket").removeClass("inputbtndisable");
                                $("#a_closeTicketToLogin").hide();
                            }
                        }
                    }
                }).always(function() {});
            } else {
                jalert("通知", "未签约作品暂不能投票", null);
            }
        });
        $("a[category='leftmenu'][index='5']").click(function() {
            hideFace();
            for (var i = 0; i < $("div[category='leftmenudiv']").length; i++) {
                if (i != 4) {
                    $($("div[category='leftmenudiv']")[i]).hide();
                }
            }
            for (var i = 0; i < $("a[category='leftmenu']").length; i++) {
                if (i != 5) {
                    if ($($("a[category='leftmenu']")[i]).hasClass('active') == true) {
                        $($("a[category='leftmenu']")[i]).removeClass("active");
                    }
                }
            }
            if (parseInt($("#hidIsFav").val()) == 1) {
                $("a[category='leftmenu'][index='2']").addClass("active");
            }
            if ($("a[category='leftmenu'][index='5']").hasClass('active') == false) {
                $("a[category='leftmenu'][index='5']").addClass("active");
                $("#divCommentOpen").fadeIn(fadeinTime,
                function() {
                    keytype = "docomment";
                    $("#txtBookComment").focus();
                });
            } else {
                $("a[category='leftmenu'][index='5']").removeClass("active");
                $("#divCommentOpen").fadeOut(fadeoutTime,
                function() {
                    keytype = "page";
                });
            }
            if ($("#divleftMenu").css("position") == "fixed") {
                $("#divCommentOpen").css("position", "fixed").css("top", divFixPos[4]);
            }
            if (window.userInfo == undefined) {
                $("#a_closeCommentToLogin").show();
                $("#btnSendComment").addClass("inputbtndisable");
                $("#btnSendComment").attr("disabled", "disabled");
            } else {
                $("#a_closeCommentToLogin").hide();
                $("#btnSendComment").removeClass("inputbtndisable");
                $("#btnSendComment").attr("disabled", false);
            }
        });
        $($("a[category='leftmenu']")[6]).click(function() {
            hideFace();
            for (var i = 0; i < $("div[category='leftmenudiv']").length; i++) {
                if (i != 5) {
                    $($("div[category='leftmenudiv']")[i]).hide();
                }
            }
            for (var i = 0; i < $("a[category='leftmenu']").length; i++) {
                if (i != 6) {
                    if ($($("a[category='leftmenu']")[i]).hasClass('active') == true) {
                        $($("a[category='leftmenu']")[i]).removeClass("active");
                    }
                }
            }
            if (parseInt($("#hidIsFav").val()) == 1) {
                $("a[category='leftmenu'][index='2']").addClass("active");
            }
            if ($(this).hasClass('active') == false) {
                $(this).addClass("active");
                if ($("#divleftMenu").css("position") == "fixed") {
                    $("#divPhoneOpen").css("position", "fixed").css("top", divFixPos[5]);
                }
                $("#divPhoneOpen").fadeToggle(fadetoggleTime);
            } else {
                $(this).removeClass("active");
                $("#divPhoneOpen").fadeToggle(fadetoggleTime);
            }
        });
        $($("a[category='leftmenu']")[7]).click(function() {
            hideFace();
            for (var i = 0; i < $("div[category='leftmenudiv']").length; i++) {
                if (i != 6) {
                    $($("div[category='leftmenudiv']")[i]).hide();
                }
            }
            for (var i = 0; i < $("a[category='leftmenu']").length; i++) {
                if (i != 7) {
                    if ($($("a[category='leftmenu']")[i]).hasClass('active') == true) {
                        $($("a[category='leftmenu']")[i]).removeClass("active");
                    }
                }
            }
            if (parseInt($("#hidIsFav").val()) == 1) {
                $("a[category='leftmenu'][index='2']").addClass("active");
            }
            if ($(this).hasClass('active') == false) {
                $(this).addClass("active");
                if ($("#divleftMenu").css("position") == "fixed") {
                    $("#divSetOpen").css("position", "fixed").css("top", divFixPos[6]);
                }
                $("#divSetOpen").fadeToggle(fadetoggleTime,
                function() {
                    if ($("#divSetOpen").css("display") == 'block') {
                        keytype = "setopen";
                    } else if ($("#divSetOpen").css("display") == 'none') {
                        keytype = "page";
                    }
                });
                $("#txtFontSize").focus();
            } else {
                $(this).removeClass("active");
                $("#divSetOpen").fadeToggle(fadetoggleTime,
                function() {
                    if ($("#divSetOpen").css("display") == 'block') {
                        keytype = "setopen";
                    } else if ($("#divSetOpen").css("display") == 'none') {
                        keytype = "page";
                    }
                });
            }
        });
        $("#a_chapterface").click(function() {
            if ($("#comment_faces").css("display") == "none") {
                var top = $("#divCommentOpen").css("top");
                var left = $("#divCommentOpen").css("left");
                if ($("#divCommentOpen").css("position") == "fixed") {
                    $("#comment_faces").css("position", "fixed").css("top", (parseInt(divFixPos[4]) + 271) + "px").css("left", parseFloat(left) - 442);
                } else {
                    $("#comment_faces").css("position", "absolute").css("top", parseFloat(top) + 275).css("left", parseFloat(left) - 442);
                }
                $("#comment_faces").show();
            } else {
                $("#comment_faces").hide();
            }
            $("#txtBookComment").click(function() {
                if ($("#comment_faces").css("display") == "block") {
                    $("#comment_faces").hide();
                }
            });
        });
    }
}
function beginFavClock() {
    $('#spanfavsec').text(parseInt($('#spanfavsec').text()) - 1);
    if (parseInt($('#spanfavsec').text()) - 1 < 0) {
        clearInterval(clock);
        var favcode = dofav(book_chaptercontent.curbid);
        if (parseInt(favcode) == 100) {
            $("a[category='leftmenu'][index='2']").html('<span class="readicon10"></span>取消收藏');
        }
        $("#hidIsFav").val(1);
        $("#divAutoFav").fadeOut(fadeoutTime,
        function() {
            $("a[category='leftmenu'][index='2']").addClass("active");
        });
    }
}
function clearFavClock() {
    clearInterval(clock);
    $("#divAutoFav").fadeOut(fadeoutTime);
}
function inputBookshelf() {
    var code = dofav(book_chaptercontent.curbid);
    if (code == 100) {
        $($("div[category='leftmenudiv']")[1]).hide();
        $("#hidIsFav").val(1);
        $("a[category='leftmenu'][index='2']").html('<span class="readicon10"></span>取消收藏');
    } else if (code == 101) {
        $("#hidIsFav").val(0);
        $("a[category='leftmenu'][index='2']").html('<span class="readicon10"></span>加入书架');
    }
}
function closeCommentOpen(islogin) {
    hideFace();
    if (islogin == 0) {
        $("#divCommentOpen").fadeOut(fadeoutTime);
        if ($("#hidPageType").val() == "content") {
            $($("a[category='leftmenu']")[5]).removeClass("active");
        }
    } else if (islogin == 1) {
        keytype = "login";
        $("#divCommentOpen").fadeOut(fadeoutTime,
        function() {
            $($("a[category='leftmenu']")[5]).removeClass("active");
            user_modellogin.showLoginDialog(6);
        });
    }
}
function showCHMenu() {
    if ($("#contentheadMenu").css("display") == "none") {
        $("#contentheadMenu").fadeIn(fadeinTime);
    } else {
        $("#contentheadMenu").fadeOut(fadeoutTime);
    }
    $("body").click(function() {
        if ($("#contentheadMenu").css("display") == "block") {
            $("#contentheadMenu").fadeOut(fadeoutTime);
        }
    });
}
function changeBgColor(color) {
    if (color == null) {
        color = 1;
    }
    $("a[category='color']").removeClass("active");
    $("a[category='color'][index='" + color + "']").addClass("active");
    rcolor = CookieUtil.getCookie('rcolor');
    if (rcolor == null) {
        rcolor = "1";
    }
    book_chaptercontent.rcolor = rcolor;
    $("body").removeClass("read_on_bgcolor_0" + rcolor);
    $("body").addClass("read_on_bgcolor_0" + color);
    $("div[category='readbg']").removeClass("readconbg_0" + rcolor);
    $("div[category='readbg']").addClass("readconbg_0" + color);
    $("#divReadAuthor").removeClass("read_on_author_0" + rcolor);
    $("#divReadAuthor").addClass("read_on_author_0" + color);
    $("a[data-type='prevchpb']").removeClass("readtextbtnlast_0" + rcolor);
    $("a[data-type='prevchpb']").addClass("readtextbtnlast_0" + color);
    $("a[data-type='nextchpb']").removeClass("readtextbtnnext_0" + rcolor);
    $("a[data-type='nextchpb']").addClass("readtextbtnnext_0" + color);
    $("a[data-type='prevchpr']").removeClass("prevbtn_0" + rcolor);
    $("a[data-type='prevchpr']").addClass("prevbtn_0" + color);
    $("a[data-type='nextchpr']").removeClass("nextbtn_0" + rcolor);
    $("a[data-type='nextchpr']").addClass("nextbtn_0" + color);
    if (color == "6") {
        $("#a_nightmodel").removeClass("off");
        if ($("#hidsign").val() == "2") {
            $("#a_nightmodel").addClass("boy");
        } else if ($("#hidsign").val() == "3") {
            $("#a_nightmodel").addClass("girl");
        }
    } else {
        if ($("#hidsign").val() == "2") {
            $("#a_nightmodel").removeClass("boy");
        } else if ($("#hidsign").val() == "3") {
            $("#a_nightmodel").removeClass("girl");
        }
        $("#a_nightmodel").addClass("off");
    }
    CookieUtil.setCookie({
        'name': 'rcolor',
        'value': color,
        'expires': 2592000,
        'path': '/content'
    });
}
function addFontSize() {
    if (parseInt($("#txtFontSize").val()) > 28) {
        return;
    }
    var cssFontSize = $("#txtFontSize").val() + "px";
    if (cssFontSize == "") {
        return;
    }
    var lineHeigh = parseFloat($("#divChpContent p").css("line-height"));
    var fontSize = parseFloat(cssFontSize);
    var unit = cssFontSize.slice( - 2);
    fontSize += 1;
    lineHeigh += 2;
    setFontSize((fontSize + unit), (lineHeigh + unit));
}
function reduceFontSize() {
    var cssFontSize = $("#txtFontSize").val() + "px";
    if (cssFontSize == "") {
        return;
    }
    var lineHeigh = parseFloat($("#divChpContent p").css("line-height"));
    var fontSize = parseFloat(cssFontSize);
    var unit = cssFontSize.slice( - 2);
    var className = $(this).attr("class");
    if (fontSize - 1 < 10) {
        return;
    }
    fontSize -= 1;
    lineHeigh -= 2;
    setFontSize((fontSize + unit), (lineHeigh + unit));
}
function setFontSize(s, l) {
    $("#divChpContent").css("font-size", s);
    $("#divChpContent p").css("font-size", s);
    $("#divChpContent").css("line-height", l);
    $("#divChpContent p").css("line-height", l);
    $("#txtFontSize").val(parseFloat(s));
    CookieUtil.setCookie({
        'name': 'fsize',
        'value': (s),
        'expires': 2592000,
        'path': '/content'
    });
    CookieUtil.setCookie({
        'name': 'lheight',
        'value': (l),
        'expires': 2592000,
        'path': '/content'
    });
}
function initUserSet() {
    if ($("#hidPageType").val() == "content") {
        var contentcolor = CookieUtil.getCookie('rcolor');
        changeBgColor(contentcolor);
        var fontSize = CookieUtil.getCookie('fsize');
        var lineHeigh = CookieUtil.getCookie('lheight');
        if (fontSize != null && lineHeigh != null) {
            setFontSize(fontSize, lineHeigh);
        }
    }
}
function showZanshang() {
    if ($("#hidPageType").val() == "fansrank") {
        $(".bodybg").fadeIn(fadeinTime,
        function() {
            $(".bodybg").click(function() {
                closePro();
            });
            $("#divShang").css("position", "fixed").css("top", "135px").css("z-index", "1001").css("left", "50%").css("margin-left", "-335px");
        });
    }
    $("#divShang").fadeToggle(fadetoggleTime,
    function() {
        if ($("#divShang").css("display") == 'block') {
            setTimeout('initProperties();', 500);
            $("li[category='selectproperties']:eq(0)").click();
            $("#txtPCount").focus();
            keytype = "zanshang";
        } else if ($("#divShang").css("display") == 'none') {
            keytype = "page";
        }
    });
}
function closeZanshang(islogin) {
    hideFace();
    if (islogin == 0) {
        if ($(".bodybg").css("display") == "block") {
            $(".bodybg").fadeOut(fadeoutTime,
            function() {
                $('#divShang').fadeOut(fadeoutTime);
            });
        } else {
            $('#divShang').fadeOut(fadeoutTime);
        }
        keytype = "page";
    } else if (islogin == 1) {
        $('#divShang').fadeOut(fadeoutTime,
        function() {
            user_modellogin.showLoginDialog(14);
        });
    }
}
function initPregress() {
    if ($("#hidPageType").val() == "chapterlist") {
        if ($("#hidBid").val() != undefined) {
            var progress = CookieUtil.getCookie('lastchapter' + $("#hidBid").val());
            if (progress != null) {
                var data = eval("(" + progress + ")");
                $("#spanReadTitle").html("我的阅读进度：" + "<a href='/content/" + data.bid + "/" + data.jid + "-" + data.cid + ".html'>" + data.title + "</a>");
                $("#spanPrecent").html(data.curpos + "/" + data.total);
            } else {
                $("#spanReadTitle").html("我的阅读进度：暂未开始");
                $("#spanPrecent").html(0 + "/" + $("#c_total").text());
            }
        }
    }
}
function nightModel() {
    if ($("#a_nightmodel").hasClass("off") == true) {
        $("#a_nightmodel").removeClass("off");
        if ($("#hidsign").val() == "2") {
            $("#a_nightmodel").addClass("boy");
        } else if ($("#hidsign").val() == "3") {
            $("#a_nightmodel").addClass("girl");
        }
        changeBgColor(6);
    } else {
        if ($("#hidsign").val() == "2") {
            $("#a_nightmodel").removeClass("boy");
        } else if ($("#hidsign").val() == "3") {
            $("#a_nightmodel").removeClass("girl");
        }
        $("#a_nightmodel").addClass("off");
        changeBgColor(1);
    }
}
function autoBuyChp(bid) {
    var url = hs_const_url.bookajax;
    $.ajax({
        url: url,
        type: 'post',
        dataType: 'json',
        async: true,
        data: {
            method: 'updateautoorderstatus',
            bid: bid
        },
        beforeSend: function() {
            $("#a_autobuy").attr("href", "javascript:void(0)");
        },
        success: function(data) {
            if (data.code == -102) {
                user_modellogin.showLoginDialog('');
            } else if (data.code == 121) {
                $("#a_autobuy").removeClass("off");
                if ($("#hidsign").val() == "2") {
                    $("#a_autobuy").addClass("boy");
                } else if ($("#hidsign").val() == "3") {
                    $("#a_autobuy").addClass("girl");
                }
            } else if (data.code == -137) {
                if ($("#hidsign").val() == "2") {
                    $("#a_autobuy").removeClass("boy");
                } else if ($("#hidsign").val() == "3") {
                    $("#a_autobuy").removeClass("girl");
                }
                $("#a_autobuy").addClass("off");
            }
        }
    }).always(function() {
        $("#a_autobuy").attr("href", "javascript:autoBuyChp(" + bid + ")");
    });
}
function initAutoChpStatus() {
    if ($("#hidPageType").val() == "bookindex") {
        var url = hs_const_url.bookajax;
        $.ajax({
            url: url,
            type: 'post',
            dataType: 'json',
            async: false,
            data: {
                method: 'getautoorderstatus',
                bid: $("#hidbid").val()
            },
            beforeSend: function() {},
            success: function(data) {
                if (data.code == -102) {
                    $("#a_autobuy").addClass("off");
                } else if (data.code == 121) {
                    $("#a_autobuy").removeClass("off");
                    if ($("#hidsign").val() == "2") {
                        $("#a_autobuy").addClass("boy");
                    } else if ($("#hidsign").val() == "3") {
                        $("#a_autobuy").addClass("girl");
                    }
                } else if (data.code == -137) {
                    if ($("#hidsign").val() == "2") {
                        $("#a_autobuy").removeClass("boy");
                    } else if ($("#hidsign").val() == "3") {
                        $("#a_autobuy").removeClass("girl");
                    }
                    $("#a_autobuy").addClass("off");
                }
            }
        }).always(function() {});
    }
}
function initIsFav() {
    if ($("#hidPageType").val() == "content") {
        var url = hs_const_url.bookajax;
        $.ajax({
            url: url,
            type: 'post',
            dataType: 'json',
            async: false,
            data: {
                method: 'checkfav',
                bid: book_chaptercontent.curbid
            },
            beforeSend: function() {},
            success: function(data) {
                if (data.code == -102) {
                    $("#hidIsFav").val(0);
                    $("a[category='leftmenu'][index='2']").html('<span class="readicon10"></span>加入书架');
                    $("a[category='leftmenu'][index='2']").removeClass('active');
                } else if (data.code == 122) {
                    $("#hidIsFav").val(1);
                    $("a[category='leftmenu'][index='2']").html('<span class="readicon10"></span>取消收藏');
                    $("a[category='leftmenu'][index='2']").addClass('active');
                } else if (data.code == -138) {
                    $("#hidIsFav").val(0);
                    $("a[category='leftmenu'][index='2']").html('<span class="readicon10"></span>加入书架');
                    $("a[category='leftmenu'][index='2']").removeClass('active');
                    if (window.userInfo != undefined) {
                        uid = window.userInfo.uid;
                        if ($("#divleftMenu").css("position") == "fixed") {
                            $("#divAutoFav").css("position", "fixed").css("top", divFixPos[1]);
                        }
                        setTimeout(function() {
                            if ($("#divleftMenu").css("position") == "fixed") {
                                $("#divAutoFav").css("position", "fixed").css("top", divFixPos[1]);
                            }
                            $("#divAutoFav").fadeIn(fadeinTime);
                            clock = setInterval("beginFavClock()", 1000);
                        },
                        15000);
                    } else {}
                }
            }
        }).always(function() {});
    }
}
function initFansRank() {
    if ($("#hidPageType").val() == "fansrank") {
        var url = hs_const_url.bookajax;
        $.ajax({
            url: url,
            type: 'post',
            dataType: 'json',
            async: false,
            data: {
                method: 'getfansrank',
                bid: $("#hidbid").val()
            },
            beforeSend: function() {},
            success: function(data) {
                if (data.code == -102) {
                    $("#divNowRank").hide();
                } else if (data.code == 123) {
                    $("#spanRank").text(data.rank == 0 ? "-": data.rank);
                    $("#a_rank").html(data.nickname);
                    $("#a_rank").attr("href", "/userspace/" + data.uid + "/0.html");
                    $("#imgRank").attr("src", $("#imgRank").attr("temp") + "fensi_" + data.groupid + ".png");
                    $("#divRankIntegral").html(data.integral);
                    $("#divNowRank").show();
                }
            }
        }).always(function() {});
    }
}
function initMyFace() {
    if ($("#a_facepath").html() != undefined) {
        setTimeout(function() {
            if (window.userInfo != undefined) {
                var faceurl = getUserFacePath(window.userInfo.uid, 'small');
                $("#imgFacePath").attr("data-original", faceurl);
                $("#imgFacePath").attr("src", faceurl);
                $("#a_facepath").attr("href", hs_const_domain.homeHost + "/userspace/u/" + window.userInfo.uid + "/index.html");
                $("#a_facepath").attr("title", (window.userInfo.nickname == "" ? window.userInfo.username: window.userInfo.nickname));
            } else {
                var uid = 0;
                var faceurl = getUserFacePath(uid, 'small');
                $("#imgFacePath").attr("data-original", faceurl);
                $("#a_facepath").attr("href", "javascript:void(0)");
            }
        },
        setOutTime);
    }
}
function initFav() {
    if ($("#hidPageType").val() == "bookindex") {
        var url = hs_const_url.bookajax;
        $.ajax({
            url: url,
            type: 'post',
            dataType: 'json',
            async: false,
            data: {
                method: 'checkfav',
                bid: $("#hidbid").val()
            },
            beforeSend: function() {},
            success: function(data) {
                if (data.code == -102) {
                    $("#a_favdone").show();
                    $("#a_favfinish").hide();
                } else if (data.code == 122) {
                    $("#a_favdone").hide();
                    $("#a_favfinish").show();
                } else if (data.code == -138) {
                    $("#a_favdone").show();
                    $("#a_favfinish").hide();
                }
            }
        }).always(function() {});
        setTimeout(function() {
            if (window.userInfo != undefined) {
                if (window.userInfo.isauthor == "1" && window.userInfo.authorid == $("#hidauthorid").val() || parseInt(window.userInfo.havepriv) == 1) {
                    $("#p_totalfav").show();
                } else {
                    $("#p_totalfav").html("&nbsp;");
                    $("#p_totalfav").hide();
                }
            } else {
                $("#p_totalfav").html("&nbsp;");
                $("#p_totalfav").hide();
            }
        },
        setOutTime);
    }
}
function long2str(v, w) {
    var vl = v.length;
    var sl = v[vl - 1] & 0xffffffff;
    for (var i = 0; i < vl; i++) {
        v[i] = String.fromCharCode(v[i] & 0xff, v[i] >>> 8 & 0xff, v[i] >>> 16 & 0xff, v[i] >>> 24 & 0xff);
    }
    if (w) {
        return v.join('').substring(0, sl);
    } else {
        return v.join('');
    }
}
function str2long(s, w) {
    var len = s.length;
    var v = [];
    for (var i = 0; i < len; i += 4) {
        v[i >> 2] = s.charCodeAt(i) | s.charCodeAt(i + 1) << 8 | s.charCodeAt(i + 2) << 16 | s.charCodeAt(i + 3) << 24;
    }
    if (w) {
        v[v.length] = len;
    }
    return v;
}
function hs_encrypt(str, key) {
    if (str == "") {
        return "";
    }
    var v = str2long(str, true);
    var k = str2long(key, false);
    var n = v.length - 1;
    var z = v[n],
    y = v[0],
    delta = 0x9E3779B9;
    var mx, e, q = Math.floor(6 + 52 / (n + 1)),
    sum = 0;
    while (0 < q--) {
        sum = sum + delta & 0xffffffff;
        e = sum >>> 2 & 3;
        for (var p = 0; p < n; p++) {
            y = v[p + 1];
            mx = (z >>> 5 ^ y << 2) + (y >>> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
            z = v[p] = v[p] + mx & 0xffffffff;
        }
        y = v[0];
        mx = (z >>> 5 ^ y << 2) + (y >>> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
        z = v[n] = v[n] + mx & 0xffffffff;
    }
    return long2str(v, false);
}
function hs_decrypt(str, key) {
    if (str == "") {
        return "";
    }
    var v = str2long(str, false);
    var k = str2long(key, false);
    var n = v.length - 1;
    var z = v[n - 1],
    y = v[0],
    delta = 0x9E3779B9;
    var mx, e, q = Math.floor(6 + 52 / (n + 1)),
    sum = q * delta & 0xffffffff;
    while (sum != 0) {
        e = sum >>> 2 & 3;
        for (var p = n; p > 0; p--) {
            z = v[p - 1];
            mx = (z >>> 5 ^ y << 2) + (y >>> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
            y = v[p] = v[p] - mx & 0xffffffff;
        }
        z = v[n];
        mx = (z >>> 5 ^ y << 2) + (y >>> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z);
        y = v[0] = v[0] - mx & 0xffffffff;
        sum = sum - delta & 0xffffffff;
    }
    return long2str(v, true);
}
function base64encode(str) {
    var out, i, len, base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var c1, c2, c3;
    len = str.length;
    i = 0;
    out = "";
    while (i < len) {
        c1 = str.charCodeAt(i++) & 0xff;
        if (i == len) {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt((c1 & 0x3) << 4);
            out += "==";
            break;
        }
        c2 = str.charCodeAt(i++);
        if (i == len) {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
            out += base64EncodeChars.charAt((c2 & 0xF) << 2);
            out += "=";
            break;
        }
        c3 = str.charCodeAt(i++);
        out += base64EncodeChars.charAt(c1 >> 2);
        out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
        out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
        out += base64EncodeChars.charAt(c3 & 0x3F);
    }
    return out;
}
function base64decode(str) {
    var c1, c2, c3, c4, base64DecodeChars = new Array( - 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
    var i, len, out;
    len = str.length;
    i = 0;
    out = "";
    while (i < len) {
        do {
            c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
        } while ( i < len && c1 == - 1 );
        if (c1 == -1) break;
        do {
            c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
        } while ( i < len && c2 == - 1 );
        if (c2 == -1) break;
        out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
        do {
            c3 = str.charCodeAt(i++) & 0xff;
            if (c3 == 61) return out;
            c3 = base64DecodeChars[c3];
        } while ( i < len && c3 == - 1 );
        if (c3 == -1) break;
        out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
        do {
            c4 = str.charCodeAt(i++) & 0xff;
            if (c4 == 61) return out;
            c4 = base64DecodeChars[c4];
        } while ( i < len && c4 == - 1 );
        if (c4 == -1) break;
        out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
    }
    return out;
}
function utf16to8(str) {
    var out, i, len, c;
    out = "";
    len = str.length;
    for (i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if ((c >= 0x0001) && (c <= 0x007F)) {
            out += str.charAt(i);
        } else if (c > 0x07FF) {
            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
            out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        } else {
            out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        }
    }
    return out;
}
function utf8to16(str) {
    var out, i, len, c;
    var char2, char3;
    out = "";
    len = str.length;
    i = 0;
    while (i < len) {
        c = str.charCodeAt(i++);
        switch (c >> 4) {
        case 0:
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
            out += str.charAt(i - 1);
            break;
        case 12:
        case 13:
            char2 = str.charCodeAt(i++);
            out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
            break;
        case 14:
            char2 = str.charCodeAt(i++);
            char3 = str.charCodeAt(i++);
            out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
            break;
        }
    }
    return out;
}
var book_chaptercontent = {
    curbid: 0,
    curjid: 0,
    curcid: 0,
    rcolor: 1,
    ordering: 0,
    chping: 0,
    needbuy: 1,
    shouquaninfo: 0,
    getChapterContent: function(bid, jid, cid, needpush) {
        $("#divReadAuthor").show();
        if (cid == 0) {
            return;
        }
        if (book_chaptercontent.chping == 0) {
            var submiturl = hs_const_url.bookajax;
            $.ajax({
                url: submiturl,
                type: 'post',
                dataType: 'json',
                async: false,
                data: {
                    method: "getchptkey",
                    bid: bid,
                    cid: cid
                },
                beforeSend: function() {
                    book_chaptercontent.chping = 1;
                    if ($("#hidPageType").val() == "content") {
                        showLoading();
                    }
                },
                success: function(keydata) {
                    key = keydata.key;
                    if (key == undefined) {
                        return;
                    }
                    $.ajax({
                        url: submiturl,
                        type: 'post',
                        dataType: 'json',
                        async: false,
                        data: {
                            method: "getchpcontent",
                            bid: bid,
                            jid: jid,
                            cid: cid
                        },
                        beforeSend: function() {
                            $("#contitletop").click();
                        },
                        success: function(data) {
                            book_chaptercontent.shouquaninfo = data.shouquaninfo;
                            book_chaptercontent.curbid = bid;
                            book_chaptercontent.curjid = jid;
                            book_chaptercontent.curcid = cid;
                            document.title = data.chptitle + " - " + $("#hidmaintitle").val();
                            if (needpush == 1) {
                                if (window.history.pushState != undefined) {
                                    var state = {
                                        bid: bid,
                                        jid: jid,
                                        cid: cid
                                    };
                                    history.pushState(state, data.chptitle + " - " + $("#hidmaintitle").val(), hs_const_domain.bookHost + "/content/" + bid + "/" + jid + "-" + cid + ".html");
                                }
                            }
                            $("#btnSendChpComment").attr("onclick", "sendCommentDetail(" + bid + ", " + cid + ", '" + data.chptitle + "')");
                            data['rcolor'] = book_chaptercontent.rcolor;
                            book_chaptercontent.changeShare(document.title, bid, jid, cid);
                            if (data.content != "") {
                                data.content = utf8to16(hs_decrypt(base64decode(data.content), key));
                                CookieUtil.setCookie({
                                    'name': 'lastchapter' + bid,
                                    'value': '{"title":"' + data.chptitle + '", "bid":"' + bid + '","jid":"' + jid + '","cid":"' + cid + '","curpos":"' + data.curpos + '","total":"' + (parseInt(data.vipchpcount) + parseInt(data.freechpcount)) + '", "addtime":"' + parseInt(new Date().getTime() / 1000) + '"}',
                                    'expires': 2592000,
                                    'path': '/'
                                });
                                $("#p_author_memo").html("作者的话：" + data.author_memo);
                            }
                            book_chaptercontent.needbuy = data.needbuy;
                            if (data.needbuy == 0 && data.content == "") {
                                data.content = "本章内容正在审核中，稍后将会开放，请耐心等待。";
                            }
                            $("#imgBarCode").attr("src", hs_const_domain.resourceHost + "/barcode" + decodeURIComponent(data.barcode));
                            var baseInfoHtml = htmldecode(template("baseInfoTpl", data));
                            var buyHtml = template("buyTpl", data);
                            var rightPagerHtml = template("rightPagerTpl", data);
                            var bottomPageHtml = template("bottomPageTpl", data);
                            setTimeout(function() {
                                closeLoading();
                                $("#divBaseInfo").html(baseInfoHtml);
                                $("#divMainBuy").html(buyHtml);
                                $("#divrightPager").html(rightPagerHtml);
                                $("#divBottomPage").html(bottomPageHtml);
                                book_chaptercontent.chping = 0;
                                $("body").show();
                            },
                            setOutTime);
                        }
                    }).always(function() {});
                }
            }).always(function() {
                $("#a_moreComment").attr("href", hs_const_domain.bookHost + "/commentdetail/" + book_chaptercontent.curcid + ".do");
                setTimeout(function() {
                    initUserSet();
                    if ($("#floatingCirclesG").css("display") == "block") {
                        closeLoading();
                        book_chaptercontent.chping = 0;
                        var topspace = (parseInt($("#contitletop").offset().top) - 3);
                        $("html,body").animate({
                            scrollTop: topspace
                        },
                        0);
                    }
                },
                setOutTime);
            });
        }
    },
    defaultChapter: function() {
        if ($("#hidPageType").val() == "content") {
            _bid = $("#hidbid").val();
            _jid = $("#hidjid").val();
            _cid = $("#hidcid").val();
            book_chaptercontent.getChapterContent(_bid, _jid, _cid, 1);
            book_chaptercontent.bindChapterKeyup();
            initUserSet();
        }
    },
    bindChapterKeyup: function() {
        $(document).bind("keydown",
        function(e) {
            e = window.event || e;
            if (e.keyCode == 116) {
                e.keyCode = 0;
                return false;
            }
        });
        $(document).keyup(function(event) {
            switch (event.keyCode) {
            case 39:
                if (keytype == "page") {
                    $("a[data-type='nextchpb']").click();
                }
                break;
            case 37:
                if (keytype == "page") {
                    $("a[data-type='prevchpb']").click();
                }
                break;
            case 13:
                if (keytype == "page") {
                    location = "/bookreader/" + book_chaptercontent.curbid + ".html";
                }
                break;
            case 116:
                if (keytype == "page") {
                    location = "/content/" + book_chaptercontent.curbid + "/" + book_chaptercontent.curjid + "-" + book_chaptercontent.curcid + ".html";
                }
                break;
            }
        });
    },
    initBodyStatus: function() {
        $("body").attr('oncontextmenu', 'return false');
        $("body").attr('ondragstart', 'return false');
        $("body").attr('onselectstart', 'return false');
        $("body").attr('onselect', 'return false');
        $("body").attr('oncopy', 'return false');
        $("body").attr('onbeforecopy', 'return false');
        $("body").attr('onmouseup', 'return false');
        $('body').bind('contextmenu',
        function() {
            return false;
        });
        $('body').bind("selectstart",
        function() {
            return false;
        });
        $(document).keydown(function(event) {
            if ((event.ctrlKey && event.which == 67) || (event.ctrlKey && event.which == 86)) {
                return false;
            }
        });
    },
    wisorder: function(buyall) {
        if (book_chaptercontent.needbuy == 0) {
            return;
        }
        if (buyall == 1) {
            book_chaptercontent.order(buyall);
            var topspace = (parseInt($("#contitletop").offset().top) - 3);
            $("div[role='dialog']").css("top", (window.screen.height / 2) - 90);
            $("html,body").animate({
                scrollTop: topspace
            },
            0);
        } else {
            book_chaptercontent.order(buyall);
        }
    },
    order: function(buyall) {
        if (book_chaptercontent.needbuy == 0) {
            return;
        }
        if (this.ordering == 0) {
            if (this.curbid != 0 && this.curjid != 0 && this.curcid != 0) {
                var orderbid = this.curbid;
                var orderjid = this.curjid;
                var ordercid = this.curcid;
                var autoorder = $("#chbAutoOrder").prop('checked');
                if (autoorder == true) {
                    autoorder = 3;
                } else {
                    autoorder = 0;
                }
                var submiturl = hs_const_url.bookajax;
                $.ajax({
                    url: submiturl,
                    type: 'post',
                    dataType: 'json',
                    async: false,
                    data: {
                        method: 'orderchapter',
                        chapterid: ordercid,
                        bid: orderbid,
                        autoorder: autoorder,
                        buyall: buyall
                    },
                    beforeSend: function() {
                        this.ordering = 1;
                    },
                    success: function(data) {
                        if (data.code == "120") {
                            book_chaptercontent.getChapterContent(orderbid, orderjid, ordercid, 0);
                        } else if (data.code == "-113") {
                            $("#p_ordertip").html("余额不足，请充值。");
                            $("#btnOrderPay").show();
                        } else if (data.code == "-134") {
                            $("#p_ordertip").html(data.msg);
                        } else if (data.code == "-135") {
                            $("#p_ordertip").html(data.msg);
                        } else if (data.code == "-136") {
                            $("#p_ordertip").html(data.msg);
                            book_chaptercontent.getChapterContent(orderbid, orderjid, ordercid, 0);
                        } else if (data.code == "-102") {}
                    }
                }).always(function() {
                    this.ordering = 0;
                });
            }
        }
    },
    initScrollBar: function() {
        if ($("#hidPageType").val() == "content") {
            if (window.history.pushState != undefined) {
                window.onpopstate = function(e) {
                    book_chaptercontent.getChapterContent(e.state.bid, e.state.jid, e.state.cid, 0);
                }
            }
            $("#divleftMenu").css("top", "3px");
            if ($("#divleftMenu").css("display") == "none") {
                $("#divleftMenu").fadeIn(fadeinTime);
            }
            $(document).scroll(function() {
                if ($("#divleftMenu").offset().top < 146) {
                    $("#divleftMenu").css("position", "absolute").css("top", "146px");
                    for (var i = 0; i < $("div[category='leftmenudiv']").length; i++) {
                        $("div[category='leftmenudiv']:eq(" + i + ")").css("position", "absolute").css("top", (parseInt(divFixPos[i]) + 146) + "px");
                    }
                    $("#divAutoFav").css("position", "absolute").css("top", (parseInt(divFixPos[1]) + 146) + "px");
                    $("#comment_faces").css("position", "absolute").css("top", (parseInt($("#divCommentOpen").css("top")) + 285) + "px");
                }
                if ($(document).scrollTop() >= 143) {
                    $("#divleftMenu").css("position", "fixed").css("top", "3px");
                    for (var i = 0; i < $("div[category='leftmenudiv']").length; i++) {
                        $("div[category='leftmenudiv']:eq(" + i + ")").css("position", "fixed").css("top", parseInt(divFixPos[i]) + "px");
                    }
                    $("#divAutoFav").css("position", "fixed").css("top", parseInt(divFixPos[1]) + "px");
                    $("#comment_faces").css("position", "fixed").css("top", (parseInt(divFixPos[4]) + 281) + "px");
                }
                var mainHeight = $("#contitletop").height() + 146;
                var scrollTop = $(document).scrollTop() + 553 + 3;
                if (scrollTop >= mainHeight) {
                    $("#divleftMenu").css("position", "absolute").css("top", (mainHeight - 553 + 3) + "px");
                    for (var i = 0; i < $("div[category='leftmenudiv']").length; i++) {
                        $("div[category='leftmenudiv']:eq(" + i + ")").css("position", "absolute").css("top", (mainHeight - 553 + 3 + parseInt(divFixPos[i])) + "px");
                    }
                    $("#divAutoFav").css("position", "absolute").css("top", (mainHeight - 553 + 3 + parseInt(divFixPos[1])) + "px");
                    $("#comment_faces").css("position", "absolute").css("top", (parseInt($("#divCommentOpen").css("top")) + 285) + "px");
                }
                var scrollTop = $("#divrightPager").offset().top + 242;
                if (scrollTop >= mainHeight) {
                    $("#divrightPager").css("position", "absolute").css("top", (mainHeight - 242) + "px");
                }
                if ((parseInt(mainHeight) - parseInt($(document).scrollTop()) + 146) >= parseInt(window.screen.height)) {
                    $("#divrightPager").css("position", "fixed").css("top", "auto");
                }
            });
        }
    },
    changeShare: function(title, bid, jid, cid) {
        $("#a_sharesina").attr('href', 'http://v.t.sina.com.cn/share/share.php?title=' + encodeURIComponent(title) + '&url=' + encodeURIComponent(hs_const_domain.bookHost + "/content/" + bid + "/" + jid + "-" + cid + ".html"));
        $("#a_shareqqzone").attr('href', 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?title=' + encodeURIComponent(title) + '&url=' + encodeURIComponent(hs_const_domain.bookHost + "/content/" + bid + "/" + jid + "-" + cid + ".html"));
        $("#a_sharerenren").attr('href', 'http://widget.renren.com/dialog/share?title=' + encodeURIComponent(title) + '&resourceUrl=' + encodeURIComponent(hs_const_domain.bookHost + "/content/" + bid + "/" + jid + "-" + cid + ".html"));
        $("#a_sharetxweibo").attr('href', 'http://v.t.qq.com/share/share.php?title=' + encodeURIComponent(title) + '&url=' + encodeURIComponent(hs_const_domain.bookHost + "/content/" + bid + "/" + jid + "-" + cid + ".html"));
    },
    showEndding: function(lzinfo) {
        $("#divReadAuthor").hide();
        var data = {
            'lzinfo': lzinfo
        };
        var enddingHtml = template("enddingTpl", data);
        $("#divBaseInfo").html(enddingHtml);
        $("a[data-type='prevchpb']").attr("onclick", "book_chaptercontent.getChapterContent(" + book_chaptercontent.curbid + ", " + book_chaptercontent.curjid + ", " + book_chaptercontent.curcid + ", 1);");
        $("a[data-type='prevchpr']").attr("onclick", "book_chaptercontent.getChapterContent(" + book_chaptercontent.curbid + ", " + book_chaptercontent.curjid + ", " + book_chaptercontent.curcid + ", 1);");
        $("a[data-type='nextchpb']").attr("onclick", "");
        $("a[data-type='nextchpb']").html("没有了");
        $("a[data-type='nextchpr']").attr("onclick", "");
        $("a[data-type='nextchpr']").html("<span class='readicon09'></span>没有了");
        $("#divMainBuy").html("");
    }
}
function showReplyList(commentid, category) {
    hideFace();
    if ($("#divReplyList" + commentid + category).css("display") == "block") {
        $("#a_togglereply" + commentid + category).removeClass('replyopen');
        $("#txtReply" + commentid + category).val("");
        $("#divReplyList" + commentid + category).slideUp(fadeinTime);
    } else {
        $("#txtReply" + commentid + category).val("");
        $("#a_togglereply" + commentid + category).addClass('replyopen');
        $("#divReplyList" + commentid + category).slideDown(fadeoutTime);
        initReply(commentid, category);
    }
}
function showReply(commentid, category) {
    hideFace();
    $("#divReplay" + commentid + category).show();
    if (window.userInfo == undefined) {
        $("#txtReply" + commentid + category).addClass("disabledtextareapl");
        $("#txtReply" + commentid + category).attr("readonly", "readonly");
        $("#btnSendReply" + commentid + category).attr("disabled", "disabled");
        $("#btnSendReply" + commentid + category).addClass("inputbtndisable");
        if ($("#a_commentlogin" + commentid + category).html() == undefined) {
            $("#spanLogintag" + commentid + category).before('<a id="a_commentlogin' + commentid + category + '" href="javascript:goToLogin(' + $("#hidsign").val() + ')" class="cred rt10">登录</a>|<a href="' + hs_const_domain.userHost + '/register.html?url=' + encodeURIComponent(location.href) + '" class="cred rt20 lf10">注册</a>');
        }
    } else {
        $("#txtReply" + commentid + category).removeClass("disabledtextareapl");
        $("#txtReply" + commentid + category).attr("readonly", false);
        $("#btnSendReply" + commentid + category).attr("disabled", false);
        $("#btnSendReply" + commentid + category).removeClass("inputbtndisable");
        initReply(commentid, category);
    }
}
function closePro() {
    $("#divShang").fadeOut(fadeoutTime,
    function() {
        $(".bodybg").fadeOut(fadeoutTime);
    });
}
function showFullComment(cid) {
    var fullcontent = $("#" + cid).attr("fullcontent");
    $("#" + cid).html(unescape(fullcontent));
}
function hideFullComment(cid) {
    var content = $("#" + cid).attr("content");
    $("#" + cid).html(unescape(content));
}
function initBookIndex() {
    if ($("#hidPageType").val() == "bookindex") {
        var progress = CookieUtil.getCookie('lastchapter' + $("#hidbid").val());
        if (progress != null) {
            var data = eval("(" + progress + ")");
            $("#a_readbook").text("继续阅读");
            $("#a_readbook").attr("href", hs_const_domain.bookHost + "/content/" + data.bid + "/" + data.jid + "-" + data.cid + ".html");
        }
    }
    if ($("#hidPageType").val() == "bookindex" || $("#hidPageType").val() == "commentlist") {
        setTimeout(function() {
            if (window.userInfo == undefined) {
                $("#span_nologin").show();
                $("#btnSendComment").addClass("inputbtndisable");
                $("#btnSendComment").attr("disabled", "disabled");
                $("#txtBookComment").addClass("disabledtextareapl");
                $("#txtBookComment").attr("readonly", "readonly");
            } else {
                $("#span_nologin").hide();
                $("#btnSendComment").removeClass("inputbtndisable");
                $("#btnSendComment").attr("disabled", false);
                $("#txtBookComment").removeClass("disabledtextareapl");
                $("#txtBookComment").attr("readonly", false);
            }
        },
        500);
    }
    if ($("#hidPageType").val() == "commentdetail") {
        setTimeout(function() {
            var comment_id = $("#hidCommentid").val();
            if (window.userInfo == undefined) {
                $("#span_nologin").show();
                $("#btnSendReply" + comment_id).addClass("inputbtndisable");
                $("#btnSendReply" + comment_id).attr("disabled", "disabled");
                $("#txtReply" + comment_id).addClass("disabledtextareapl");
                $("#txtReply" + comment_id).attr("readonly", "readonly");
            } else {
                $("#span_nologin").hide();
                $("#btnSendReply" + comment_id).removeClass("inputbtndisable");
                $("#btnSendReply" + comment_id).attr("disabled", false);
                $("#txtReply" + comment_id).removeClass("disabledtextareapl");
                $("#txtReply" + comment_id).attr("readonly", false);
            }
        },
        500);
    }
}
function getMorePageReply(prebegin, commentid, type) {
    hideFace();
    var curshow = (prebegin - 1) * 5;
    $.ajax({
        url: hs_const_url.bookajax,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'getreply',
            commentid: commentid,
            curshow: curshow
        },
        beforeSend: function() {
            for (var i = $("ul[sign='" + type + "'] li[category='reply" + commentid + "']").length - 1; i >= 0; i--) {
                $($("ul[sign='" + type + "'] li[category='reply" + commentid + "']")[i]).remove();
            }
        },
        success: function(data) {
            if (data.code == -102) {
                jalert("通知", data.msg,
                function() {
                    goToLogin($("#hidsign").val());
                });
            } else if (data.code == -120) {
                jalert("通知", data.msg, null);
            } else if (data.code == 110) {
                for (var i = 0; i < data.replylist.length; i++) {
                    var cururl = "";
                    if (parseInt(data.replylist[i].uid) != 0) {
                        cururl = " href='" + hs_const_domain.bookHost + "/userspace/u/" + data.replylist[i].uid + "/index.html' title='" + (data.replylist[i].nickname == "" ? data.replylist[i].username: data.replylist[i].nickname) + "' target='_blank'";
                    } else {
                        cururl = " href='javascript:void(0)' ";
                    }
                    $("#liReply" + commentid + type).before("<li category='reply" + data.replylist[i].comment_id + "' class='clearfix'><div class='right'><p class='author2'>" + " <a " + cururl + " class='" + ($("#hidsign").val() == "2" ? "cboy": "cgirl") + "'>" + (data.replylist[i].nickname == "" ? data.replylist[i].username: data.replylist[i].nickname) + "</a></p><p>" + (data.replylist[i].forbidden_flag == 1 ? "内容审核中": data.replylist[i].content) + "</p><div class='dbhuifu clearfix'><span class='fllf c2'>" + getDateDiff(data.replylist[i].creation_date) + "</span><span class='allcomnum c2  rt20 lf10'>&nbsp;</span><a href='javascript:void(0)' class='c2 lf10'>" + (curshow + i + 1) + "楼</a></div></div></li>");
                }
                $("#divReplyPage" + commentid + type).html("");
                var str = "";
                for (var i = 1; i <= data.totalpage; i++) {
                    if (i == prebegin) {
                        str += "<a class='active'>" + i + "</a>";
                    } else {
                        str += "<a href=\"javascript:getMorePageReply(" + i + "," + commentid + ",'" + type + "');\">" + i + "</a>";
                    }
                }
                $("#divReplyPage" + commentid + type).html(str);
            }
        }
    }).always(function() {});
};
var hs_home_ajax = {};
var hs_home = {};
$(document).ready(function() {
    initFoucsMap();
    bindSwitchButton();
    hs_bookroom.initBookroom();
    setTimeout("initSpacehead();", 500);
});
var imgChangeTime = 3000;
var imgFadeoutTime = 0;
var imgFadeintTime = 0;
var clock;
function initFoucsMap() {
    if ($("#hidPageType").val() == "index") {
        var imagelist = $("#p_s_images img");
        if (imagelist.html() != undefined) {
            clock = setInterval("changeImages()", imgChangeTime);
            imagelist.on("click mouseover",
            function() {
                if ($(this).attr('class').indexOf('active') != -1) {
                    clearInterval(clock);
                    return;
                }
                clearInterval(clock);
                imagelist.removeClass("active");
                $(this).addClass("active");
                $("#a_catename").text(unescape($(this).attr("catename")));
                $("#a_catename").attr("title", unescape($(this).attr("catename")));
                $("#a_intro").text(unescape($(this).attr("intro")));
                $("#a_intro").attr("title", unescape($(this).attr("intro")));
                var newurl = hs_const_domain.homeHost + "/book/" + $(this).attr("bid") + "/";
                $("#aFoucsLarge").attr("href", newurl);
                $("#a_catename").attr("href", newurl);
                $("#a_intro").attr("href", newurl);
                var largeImgPath = $(this).attr("src").replace("small", "bigdft");
                $("#imgFoucsLarge").fadeOut(imgFadeoutTime,
                function() {
                    $("#imgFoucsLarge").attr("src", largeImgPath);
                });
                var imgFoucsTitle = unescape($(this).attr("catename"));
                $("#imgFoucsLarge").fadeIn(imgFadeintTime,
                function() {
                    $("#imgFoucsLarge").attr("title", imgFoucsTitle);
                });
            });
            imagelist.on("mouseout",
            function() {
                clock = setInterval("changeImages()", imgChangeTime);
            });
        }
    }
}
function changeImages() {
    var activeimg = $('#p_s_images .active');
    var nextimg = ($('#p_s_images .active').next().length > 0) ? $('#p_s_images .active').next() : $('#p_s_images img:first');
    activeimg.removeClass('active');
    nextimg.addClass('active');
    $("#a_catename").text(unescape(nextimg.attr("catename")));
    $("#a_catename").attr("title", unescape(nextimg.attr("catename")));
    $("#a_intro").text(unescape(nextimg.attr("intro")));
    $("#a_intro").attr("title", unescape(nextimg.attr("intro")));
    var newurl = hs_const_domain.homeHost + "/book/" + nextimg.attr("bid") + "/";
    $("#aFoucsLarge").attr("href", newurl);
    $("#a_catename").attr("href", newurl);
    $("#a_intro").attr("href", newurl);
    var largeImgPath = nextimg.attr("src").replace("small", "bigdft");
    $("#imgFoucsLarge").fadeOut(imgFadeoutTime,
    function() {
        $("#imgFoucsLarge").attr("src", largeImgPath);
        $("#imgFoucsLarge").attr("title", unescape(nextimg.attr("catename")));
    });
    $("#imgFoucsLarge").fadeIn(imgFadeintTime);
}
function bindSwitchButton() {
    commonSwitch("nsqt", "ul", 1);
    commonSwitch("zxzp", "div");
    commonSwitch("nantop", "ul", 2);
    commonSwitch("nvtop", "ul");
    commonSwitch("zhuanqu", "ul");
    hs_home.switchdiv("ticket", "span", "div", "active");
    hs_home.switchdiv("sales", "span", "div", "active");
    hs_home.switchdiv("update", "span", "div", "active");
    hs_home.switchdiv("fav", "span", "div", "active");
    hs_home.switchdiv("hit", "span", "div", "active");
    hs_home.switchdiv("fansrec", "span", "div", "active");
    hs_home.switchdiv("flower", "span", "div", "active");
    hs_home.switchdiv("pro", "span", "div", "active");
    hs_home.switchdiv("fansvalue", "span", "div", "active");
}
hs_home = {
    switchdiv: function(c, t, st, cn) {
        if ($(t + "[category='" + c + "']").length > 0) {
            $(t + "[category='" + c + "']").on("click mousemove",
            function() {
                $(t + "[category='" + c + "']").removeClass(cn);
                $(this).addClass(cn);
                $(st + "[category='" + c + "list']").hide();
                $(st + "[category='" + c + "list'][index='" + $(this).attr("index") + "']").show();
            });
        }
    }
}
hs_bookroom = {
    nanclassp: 0,
    nanclass: 0,
    nvclassp: 0,
    nvclass: 0,
    free: 0,
    finish: 0,
    charnum: 0,
    updatetime: 0,
    page: 1,
    pagesize: 15,
    order: 1,
    searching: 0,
    totalpage: 0,
    allowkey: 0,
    cid: 0,
    free: 0,
    showSub: function(id) {
        this.parentid = id;
        if ($("div[category='nansub'][classid='" + id + "']").css("display") == "none") {
            for (var i = 0; i < $("div[category='nansub']").length; i++) {
                if ($($("div[category='nansub']")[i]).attr("classid") != id) {
                    $($("div[category='nansub']")[i]).hide();
                    $("#a_class" + $($("div[category='nansub']")[i]).attr("classid")).removeClass("current");
                } else {
                    if ($($("div[category='nansub']")[i]).css("display") == "none") {
                        $($("div[category='nansub']")[i]).show();
                        $("#a_class" + $($("div[category='nansub']")[i]).attr("classid")).addClass("current");
                    }
                }
            }
        } else {
            this.hideSub();
        }
    },
    hideSub: function() {
        $(".current").removeClass("current");
        $("div[category='nansub']").hide();
    },
   
    removeFree: function(free) {
        $("span[category='free'][sign='" + free + "']").remove();
        $("a[category='free'][sign='" + free + "']").removeClass("active");
        $("a[category='free'][sign='0']").addClass("active");
        this.free = 0;
        this.searchBook();
    },
    setFinish: function(finish, issearch) {
        this.order = 0;
        if (finish != this.finish) {
            $("a[category='finish'][sign='" + this.finish + "']").removeClass('active');
            $("a[category='finish'][sign='" + finish + "']").addClass('active');
            this.finish = finish;
            if (this.finish != 0) {
                var classname = "";
                if (this.finish == 1) {
                    classname = "已完结";
                } else if (this.finish == 2) {
                    classname = "连载中";
                }
                $("span[category='finish']").remove();
                $("#divTag").append("<span category='finish' sign='" + finish + "'><a href='javascript:void(0)'>" + classname + "</a><a href='javascript:hs_bookroom.removeFinish(" + finish + ")' class='delete'></a></span>");
            } else {
                $("span[category='finish']").remove();
            }
        }
        this.hideSub();
        if (issearch == 1) {
            this.searchBook();
        }
    },
    removeFinish: function(finish) {
        $("span[category='finish'][sign='" + finish + "']").remove();
        $("a[category='finish'][sign='" + finish + "']").removeClass("active");
        $("a[category='finish'][sign='0']").addClass("active");
        this.finish = 0;
        this.searchBook();
    },
    setCharnum: function(charnum, issearch) {
        this.order = 0;
        if (charnum != this.charnum) {
            $("a[category='charnum'][sign='" + this.charnum + "']").removeClass('active');
            $("a[category='charnum'][sign='" + charnum + "']").addClass('active');
            this.charnum = charnum;
            if (this.charnum != 0) {
                var classname = "";
                if (this.charnum == 1) {
                    classname = "30万字以下";
                } else if (this.charnum == 2) {
                    classname = "30-50万字";
                } else if (this.charnum == 3) {
                    classname = "50-100万字";
                } else if (this.charnum == 4) {
                    classname = "100万字以上";
                }
                $("span[category='charnum']").remove();
                $("#divTag").append("<span category='charnum' sign='" + charnum + "'><a href='javascript:void(0)'>" + classname + "</a><a href='javascript:hs_bookroom.removeCharnum(" + charnum + ")' class='delete'></a></span>");
            } else {
                $("span[category='charnum']").remove();
            }
        }
        this.hideSub();
        if (issearch == 1) {
            this.searchBook();
        }
    },
    removeCharnum: function(charnum) {
        $("span[category='charnum'][sign='" + charnum + "']").remove();
        $("a[category='charnum'][sign='" + charnum + "']").removeClass("active");
        $("a[category='charnum'][sign='0']").addClass("active");
        this.charnum = 0;
        this.searchBook();
    },
    setUpdatetime: function(updatetime, issearch) {
        this.order = 0;
        if (updatetime != this.updatetime) {
            $("a[category='updatetime'][sign='" + this.updatetime + "']").removeClass('active');
            $("a[category='updatetime'][sign='" + updatetime + "']").addClass('active');
            this.updatetime = updatetime;
            if (this.updatetime != 0) {
                var classname = "";
                if (this.updatetime == 1) {
                    classname = "三日内";
                } else if (this.updatetime == 2) {
                    classname = "七日内";
                } else if (this.updatetime == 3) {
                    classname = "半月内";
                } else if (this.updatetime == 4) {
                    classname = "一月内";
                }
                $("span[category='updatetime']").remove();
                $("#divTag").append("<span category='updatetime' sign='" + updatetime + "'><a href='javascript:void(0)'>" + classname + "</a><a href='javascript:hs_bookroom.removeUpdatetime(" + updatetime + ")' class='delete'></a></span>");
            } else {
                $("span[category='updatetime']").remove();
            }
        }
        this.hideSub();
        if (issearch == 1) {
            this.searchBook();
        }
    },
    removeUpdatetime: function(updatetime) {
        $("span[category='updatetime'][sign='" + updatetime + "']").remove();
        $("a[category='updatetime'][sign='" + updatetime + "']").removeClass("active");
        $("a[category='updatetime'][sign='0']").addClass("active");
        this.updatetime = 0;
        this.searchBook();
    },

    setNvclass: function(nvclassp, nvclass, issearch) {
        this.order = 0;
        if ($("span[category='nvclass'][psign='" + nvclassp + "'][sign='" + nvclass + "']").html() == undefined) {
            if (parseInt(nvclassp) == 0 && parseInt(nvclass) == 0) {
                $("span[category='nvclass']").remove();
                $("a[category='nvclass']").removeClass('active');
                $("a[category='nvclass'][sign='0']").addClass('active');
            } else {
                if ($("span[category='nvclass'][psign='" + nvclassp + "'][sign='" + nvclass + "']").length == 0) {
                    $("a[category='nvclass'][sign='0']").removeClass('active');
                    $("a[category='nvclass'][sign='" + nvclass + "']").addClass('active');
                    var classname = $("a[category='nvclass'][sign='" + nvclass + "']").html();
                    $("#divTag").append("<span category='nvclass' psign='" + nvclassp + "' sign='" + nvclass + "'><a href='javascript:void(0)'>" + classname + "</a><a href='javascript:hs_bookroom.removeNvclass(" + nvclass + ")' class='delete'></a></span>");
                }
            }
            this.hideSub();
            this.initClass();
            if (issearch == 1) {
                this.searchBookc(nvclass);
            }
        } else {
            this.removeNvclass(nvclass);
        }
    },
    removeNvclass: function(nvclass) {
        $("span[category='nvclass'][sign='" + nvclass + "']").remove();
        $("a[category='nvclass'][sign='" + nvclass + "']").removeClass("active");
        if ($("span[category='nvclass']").length == 0) {
            $("a[category='nvclass'][sign='0']").addClass("active");
        }
        this.initClass();
        this.searchBookc();
    },
    initNvclass: function() {
        this.nvclass = "";
        this.nvclassp = "";
        if ($("span[category='nvclass']").length > 0) {
            for (var i = 0; i < $("span[category='nvclass']").length; i++) {
                if (i != $("span[category='nvclass']").length - 1) {
                    this.nvclass += $($("span[category='nvclass']")[i]).attr("sign") + ",";
                    this.nvclassp += $($("span[category='nvclass']")[i]).attr("psign") + ",";
                } else {
                    this.nvclass += $($("span[category='nvclass']")[i]).attr("sign");
                    this.nvclassp += $($("span[category='nvclass']")[i]).attr("psign");
                }
            }
        } else {
            this.nvclass = "";
            this.nvclassp = "";
        }
    },
    setNanclass: function(nanclassp, nanclass, issearch) {
        this.order = 0;
        if ($("span[category='nanclass'][psign='" + nanclassp + "'][sign='" + nanclass + "']").html() == undefined) {
            if (parseInt(nanclassp) == 0 && parseInt(nanclass) == 0) {
                this.hideSub();
                $("span[category='nanclass']").remove();
                $("a[category='nanclass']").removeClass('active');
                $("a[category='nanpclass']").removeClass('active');
                $("a[category='nanclass'][sign='0']").addClass('active');
            } else {
                if ($("span[category='nanclass'][psign='" + nanclassp + "'][sign='" + nanclass + "']").length == 0) {
                    $("a[category='nanclass'][sign='0']").removeClass('active');
                    $("a[category='nanclass'][sign='" + nanclass + "']").addClass('active');
                    $("#a_class" + nanclassp).addClass('active');
                    var classname = $("a[category='nanclass'][sign='" + nanclass + "']").html();
                    $("#divTag").append("<span category='nanclass' psign='" + nanclassp + "' sign='" + nanclass + "'><a href='javascript:void(0)'>" + classname + "</a><a href='javascript:hs_bookroom.removeNanclass(" + nanclass + ")' class='delete'></a></span>");
                }
            }
            this.initClass();
            if (issearch == 1) {
                this.searchBook();
            }
        } else {
            this.removeNanclass(nanclass);
        }
    },
    removeNanclass: function(nanclass) {
        $("a[category='nanclass'][sign='" + nanclass + "']").removeClass("active");
        var psign = $("span[category='nanclass'][sign='" + nanclass + "']").attr("psign");
        $("span[category='nanclass'][sign='" + nanclass + "']").remove();
        if ($("span[category='nanclass'][psign='" + psign + "']").length == 0) {
            $("#a_class" + psign).removeClass('active');
        }
        if ($("span[category='nanclass']").length == 0) {
            $("a[category='nanclass'][sign='0']").addClass("active");
        }
        this.initClass();
        this.searchBook();
    },
    initNanclass: function() {
        this.nanclass = "";
        this.nanclassp = "";
        if ($("span[category='nanclass']").length > 0) {
            for (var i = 0; i < $("span[category='nanclass']").length; i++) {
                if (i != $("span[category='nanclass']").length - 1) {
                    this.nanclass += $($("span[category='nanclass']")[i]).attr("sign") + ",";
                    this.nanclassp += $($("span[category='nanclass']")[i]).attr("psign") + ",";
                } else {
                    this.nanclass += $($("span[category='nanclass']")[i]).attr("sign");
                    this.nanclassp += $($("span[category='nanclass']")[i]).attr("psign");
                }
            }
        } else {
            this.nanclass = "";
            this.nanclassp = "";
        }
    },
    initClass: function() {
        this.initNanclass();
        this.initNvclass();
    },
    setPage: function(page) {
        if (hs_bookroom.searching == 0) {
            this.page = page;
        }
    },
    curfavbid: 0,
    dofav: function(bid) {
        this.curfavbid = bid;
        $.ajax({
            url: hs_const_url.bookajax,
            type: 'post',
            dataType: 'json',
            async: true,
            data: {
                method: "dofavorite",
                bid: bid
            },
            success: function(data) {
                if (data.code == -102) {
                    user_modellogin.showLoginDialog(12);
                } else if (data.code == 100) {
                    $("#a_dofav" + bid).html("取消收藏");
                } else if (data.code == 101) {
                    $("#a_dofav" + bid).html("加入书架");
                }
            }
        });
    },
    setTag: function(tag) {
        this.order = 0;
        $("#txtKeyword").val(tag);
        $("#selKeywordtype").val(5);
        this.searchBook();
    },
    setOrder: function(order) {
        this.order = order;
        this.searchBook();
    },
    searchBookc: function(cid = 0,free = 0){
    	// alert(cid);

    	$.ajaxSetup({
	        headers: {
	            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
	        }
		});

    	$.ajax({
        url:"/bookstore/books",//请求的url地址
        data:{cid:cid,isend:free},//传递的参数
        dataType:'json',//返回的数据的格式
        type:'get',//请求的方式
        success:function(data){
	         var books = data;

	         for (var i = 0; i < books.length; i++) {
	         	if(books[i]['isend'] == 0){
	         		books[i]['isend'] = '完结';
	         	}else{
	         		books[i]['isend'] = '连载';
	         	}
	         	 var ht = "<li><div class='left'><a href='http://www.hongshu.com/book/72104/' target='_blank' class='img' title='"+books[i]['b_name']+"'><img src='"+books[i]['b_pic']+"'></a> </div><div class='right lf20'><h4 class='yahei '><a href='跳转详情页传书籍id' target='_blank' title='"+books[i]['b_name']+"'>"+books[i]['b_name']+"</a></h4><p>作者：<a href='javascript:void(0)' title='zhangsan'>"+books[i]['name']+"</a></p><p>类别："+books[i]['cname']+"</p><p>是否连载:"+books[i]['isend']+"</p><p>书籍简介："+books[i]['b_desc']+"</p></div><div class='readbombtn2 top20 flrt clearfix'><a href='http://www.hongshu.cn/content/content?id=2&amp;z_id=12' target='_blank'>阅读</a><a id='a_dofav3217' href='http://www.hongshu.cn/join?id=2&amp;z_id=12' class='continueread2'>放入书架</a></div></li>";
	         	
	         	
	         	$('#booklist').append(ht);			
	         };
	    },
	    error:function(){
	    //请求失败时执行
	        // alert('出错啦 思密达');
	    },
	    //请求超时时间,必须时异步请求时才会生效
	    timeout:2000,
	    async:true//true异步 false同步
	    });
    }, 

  //   searchBooke: function(end){
  //   	// alert(cid);
  //   	$.ajaxSetup({
	 //        headers: {
	 //            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
	 //        }
		// });

  //   	$.ajax({
  //       url:"/bookstore/books",//请求的url地址
  //       data:{isend:end},//传递的参数
  //       dataType:'json',//返回的数据的格式
  //       type:'get',//请求的方式
  //       success:function(data){
	 //         var books = data;

	 //         for (var i = 0; i < books.length; i++) {
	 //         	if(books[i]['isend'] == 0){
	 //         		books[i]['isend'] = '完结';
	 //         	}else{
	 //         		books[i]['isend'] = '连载';
	 //         	}
	 //         	 var ht = "<li><div class='left'><a href='http://www.hongshu.com/book/72104/' target='_blank' class='img' title='"+books[i]['b_name']+"'><img src='"+books[i]['b_pic']+"'></a> </div><div class='right lf20'><h4 class='yahei '><a href='跳转详情页传书籍id' target='_blank' title='"+books[i]['b_name']+"'>"+books[i]['b_name']+"</a></h4><p>作者：<a href='javascript:void(0)' title='zhangsan'>"+books[i]['name']+"</a></p><p>类别："+books[i]['cname']+"</p><p>是否连载:"+books[i]['isend']+"</p><p>书籍简介："+books[i]['b_desc']+"</p></div><div class='readbombtn2 top20 flrt clearfix'><a href='http://www.hongshu.cn/content/content?id=2&amp;z_id=12' target='_blank'>阅读</a><a id='a_dofav3217' href='http://www.hongshu.cn/join?id=2&amp;z_id=12' class='continueread2'>放入书架</a></div></li>";
	         	
	         	
	 //         	$('#booklist').append(ht);			
	 //         };
	 //    },
	 //    error:function(){
	 //    //请求失败时执行
	 //        // alert('出错啦 思密达');
	 //    },
	 //    //请求超时时间,必须时异步请求时才会生效
	 //    timeout:2000,
	 //    async:true//true异步 false同步
	 //    });
  //   }, 

  	// searchBookc: search(cid),

    // searchBook: function() {
    //     if (hs_bookroom.searching == 0) {
    //         hs_bookroom.searching = 1;
    //         var method = "search";
    //         var pclassid = this.nanclassp + (this.nanclassp != "" && this.nvclassp != "" ? ",": "") + this.nvclassp;
    //         var classid = this.nanclass + (this.nanclass != "" && this.nvclass != "" ? ",": "") + this.nvclass;
    //         var free = this.free;
    //         var finish = this.finish;
    //         var charnum = this.charnum;
    //         var updatetime = this.updatetime;
    //         var keyword = $("#txtKeyword").val();
    //         var keywordtype = $("#selKeywordtype").val();
    //         var order = this.order;
    //         var page = this.page;
    //         var pagesize = this.pagesize;
    //         var submiturl = hs_const_url.homeajax;
    //         $.ajax({
    //             url: submiturl,
    //             type: 'post',
    //             dataType: 'json',
    //             async: false,
    //             data: {
    //                 method: encodeURIComponent(method),
    //                 Pclassids: encodeURIComponent(pclassid),
    //                 classids: encodeURIComponent(classid),
    //                 free: encodeURIComponent(free),
    //                 finish: encodeURIComponent(finish),
    //                 charnum: encodeURIComponent(charnum),
    //                 updatetime: encodeURIComponent(updatetime),
    //                 keyword: keyword,
    //                 keywordtype: encodeURIComponent(keywordtype),
    //                 order: encodeURIComponent(order),
    //                 page: encodeURIComponent(page),
    //                 pagesize: encodeURIComponent(pagesize)
    //             },
    //             beforeSend: function() {
    //                 showLoading();
    //             },
    //             success: function(data) {
    //                 if (data.bookinfo == null) {
    //                     hs_bookroom.searching = 0;
    //                     $("#divBookList").html("没有搜索到您想要的书籍，请换个条件试试吧~");
    //                     setTimeout(function() {
    //                         closeLoading();
    //                     },
    //                     setOutTime);
    //                     return;
    //                 }
    //                 var strpagelist = "";
    //                 var rollpage = 11;
    //                 var now_cool_page = parseInt(rollpage) / 2;
    //                 var now_cool_page_ceil = Math.ceil(now_cool_page);
    //                 var temppage = 0;
    //                 for (var i = 1; i <= rollpage; i++) {
    //                     if ((parseInt(page) - now_cool_page) <= 0) {
    //                         temppage = i;
    //                     } else if ((parseInt(page) + now_cool_page - 1) >= data.pagecount) {
    //                         temppage = parseInt(data.pagecount) - parseInt(rollpage) + parseInt(i);
    //                     } else {
    //                         temppage = parseInt(page) - parseInt(now_cool_page_ceil) + parseInt(i);
    //                     }
    //                     if (temppage > 0) {
    //                         if (temppage <= data.pagecount) {
    //                             strpagelist += temppage + ' : ' + parseInt(temppage) + ',';
    //                         } else {
    //                             break;
    //                         }
    //                     }
    //                 }
    //                 if (strpagelist.length > 0) {
    //                     strpagelist = strpagelist.substring(0, strpagelist.length - 1);
    //                 }
    //                 strpagelist = eval('({' + strpagelist + '})');
    //                 data['pagelist'] = strpagelist;
    //                 data["curpage"] = page;
    //                 if (data["pagecount"] == 0) {
    //                     data["pagecount"] = 1;
    //                 }
    //                 hs_bookroom.totalpage = parseInt(data["pagecount"]);
    //                 if (data.bookinfo != null) {
    //                     var bids = "";
    //                     for (var i = 0; i < data.bookinfo.length; i++) {
    //                         if (i == (data.bookinfo.length - 1)) {
    //                             bids += data.bookinfo[i]['bid'];
    //                         } else {
    //                             bids += data.bookinfo[i]['bid'] + ",";
    //                         }
    //                     }
    //                     $.ajax({
    //                         url: submiturl,
    //                         type: 'post',
    //                         dataType: 'json',
    //                         async: false,
    //                         data: {
    //                             method: escape("getfavstatus"),
    //                             bids: escape(bids)
    //                         },
    //                         beforeSend: function() {},
    //                         success: function(favdata) {
    //                             for (var i = 0; i < data.bookinfo.length; i++) {
    //                                 data.bookinfo[i]['isfav'] = favdata.favstatus.split(',')[i];
    //                             }
    //                         }
    //                     }).always(function() {});
    //                     $.ajax({
    //                         url: submiturl,
    //                         type: 'post',
    //                         dataType: 'json',
    //                         async: false,
    //                         data: {
    //                             method: escape("getchpcount"),
    //                             bids: escape(bids)
    //                         },
    //                         beforeSend: function() {},
    //                         success: function(chpdata) {
    //                             for (var i = 0; i < data.bookinfo.length; i++) {
    //                                 data.bookinfo[i]['chapternum'] = chpdata.chpcount.split(',')[i];
    //                             }
    //                         }
    //                     }).always(function() {});
    //                 }
    //                 data['userHost'] = hs_const_domain.userHost;
    //                 data['homeHost'] = hs_const_domain.homeHost;
    //                 data['payHost'] = hs_const_domain.payHost;
    //                 data['bookHost'] = hs_const_domain.bookHost;
    //                 data['ggHost'] = hs_const_domain.ggHostName;
    //                 data['mmHost'] = hs_const_domain.mmHostName;
    //                 var html = template("bookroomTpl", data);
    //                 var wordarr = keyword.split(' ');
    //                 if (wordarr.length > 0 && keyword != "") {
    //                     $("span[category='keyword']").remove();
    //                     for (var i = 0; i < wordarr.length; i++) {
    //                         if ($.trim(wordarr[i]) != "" && !$.isNumeric(wordarr[i])) {
    //                             $("#divTag").append("<span category='keyword' value='" + $.trim(wordarr[i]) + "'><a href='javascript:void(0)'>" + $.trim(wordarr[i]) + "</a><a href='javascript:hs_bookroom.removeKeyword(\"" + $.trim(wordarr[i]) + "\")' class='delete'></a></span>");
    //                             html = html.replace(eval("/" + $.trim(wordarr[i]).toUpperCase() + "/g"), "<font style='color:red'>" + $.trim(wordarr[i]).toUpperCase() + "</font>");
    //                         }
    //                     }
    //                 }
    //                 $("#txtKeyword").val(keyword);
    //                 hs_bookroom.initTitle();
    //                 setTimeout(function() {
    //                     closeLoading();
    //                     hs_bookroom.searching = 0;
    //                     $("#divBookList").html(html);
    //                     $("#selOrder").val(order);
    //                 },
    //                 setOutTime);
    //             }
    //         }).always(function() {
    //             setTimeout(function() {
    //                 var topspace = (parseInt($("#divBookRoomSign").offset().top) - 3);
    //                 $("html,body").animate({
    //                     scrollTop: topspace
    //                 },
    //                 1000,
    //                 function() {});
    //             },
    //             setOutTime);
    //             closeLoading();
    //         });
    //     }
    // },
    removeKeyword: function(keyword) {
        var curkeyword = $.trim($("#txtKeyword").val());
        var newkeyword = $.trim(curkeyword.replace(eval("/" + $.trim(keyword) + "/g"), ""));
        $("span[category='keyword'][value='" + $.trim(keyword) + "']").remove();
        $("#txtKeyword").val(newkeyword);
        this.searchBook();
    },
    setKeyword: function(keyword) {
        this.order = 0;
        $("#txtKeyword").val(keyword);
        $("#selKeywordtype").val(1);
        this.searchBook();
    },
    initBookroom: function() {
        if ($("#hidPageType").val() == "bookroom") {
            $("#txtKeyword").focus(function() {
                hs_bookroom.allowkey == 1;
            });
            $("#txtKeyword").blur(function(event) {
                hs_bookroom.allowkey == 0;
            });
            $(document).keyup(function(event) {
                switch (event.keyCode) {
                case 39:
                    if (hs_bookroom.allowkey == 0) {
                        if (parseInt(hs_bookroom.page) + 1 <= parseInt(hs_bookroom.totalpage)) {
                            hs_bookroom.setPage(parseInt(hs_bookroom.page) + 1);
                            hs_bookroom.searchBook();
                        }
                    }
                    break;
                case 37:
                    if (hs_bookroom.allowkey == 0) {
                        if (parseInt(hs_bookroom.page) - 1 > 0) {
                            hs_bookroom.setPage(parseInt(hs_bookroom.page) - 1);
                            hs_bookroom.searchBook();
                        }
                    }
                    break;
                }
            });
            $("body").click(function() {
                hs_bookroom.hideSub();
            });
            $("#txtKeyword").keyup(function(event) {
                switch (event.keyCode) {
                case 13:
                    hs_bookroom.order = 0;
                    hs_bookroom.searchBook();
                    break;
                }
            });
            if ($("#hidFormurlPcid").val() != "" && $("#hidFormurlcid").val() != "") {
                if ($("#hidFormurlPcid").val() != "2") {
                    hs_bookroom.setNanclass($("#hidFormurlPcid").val(), $("#hidFormurlcid").val(), 0);
                } else {
                    hs_bookroom.setNvclass($("#hidFormurlPcid").val(), $("#hidFormurlcid").val(), 0);
                }
            }
            hs_bookroom.initClass();
            if ($("#hidFormurlfinish").val() != "") {
                hs_bookroom.setFinish($("#hidFormurlfinish").val(), 0);
            }
            if ($("#hidFormurlcharnum").val() != "") {
                hs_bookroom.setCharnum($("#hidFormurlcharnum").val(), 0);
            }
            if ($("#hidFormurlupdatetime").val() != "") {
                hs_bookroom.setUpdatetime($("#hidFormurlupdatetime").val(), 0);
            }
            var keyword = $.trim($("#txtKeyword").val());
            if (keyword != "" && keyword != undefined && keyword != "undefined") {
                hs_bookroom.order = 0;
            } else {
                hs_bookroom.order = 4;
            }
            hs_bookroom.searchBook();
            $("#hidFormurlPcid").val("");
            $("#hidFormurlcid").val("");
            $("#hidFormurlfinish").val("");
            $("#hidFormurlcharnum").val("");
            $("#hidFormurlupdatetime").val("");
        }
    },
    conditionReset: function() {
        this.setNanclass(0, 0, 0);
        this.setNvclass(0, 0, 0);
        this.setFree(0, 0);
        this.setFinish(0, 0);
        this.setCharnum(0, 0);
        this.setUpdatetime(0, 0);
        this.order = 1;
        $("#txtKeyword").val("");
        $("span[category='keyword']").remove();
        $("#selKeywordtype").val(1);
    },
    initTitle: function() {
        var classname = "";
        for (var i = 0; i < $("#divTag span").length; i++) {
            classname += $($($("#divTag span")[i]).children("a:eq(0)")).html() + " - "
        }
        document.title = classname + $("#hidMaintitle").val();
    }
}
var hs_user = {
    toggleMenu: function(i, t, c) {
        for (var j = 0; j < $(t + "[category='" + c + "']").length; j++) {
            if (i != j) {
                $(t + "[category='" + c + "'][index='" + j + "']").hide();
            }
        }
        $(t + "[category='" + c + "'][index=" + i + "]").toggle();
        $("body").click(function() {
            if ($(t + "[category='" + c + "'][index=" + i + "]").css("display") == "block") {
                $(t + "[category='" + c + "'][index=" + i + "]").hide();
            }
        });
    }
}
var hs_user_ajax = {};
hs_user_ajax.doFavorite = function(bid) {
    var submiturl = hs_const_url.homeajax;
    $.ajax({
        url: submiturl,
        type: 'post',
        dataType: 'json',
        data: {
            method: 'dofavorite',
            bid: bid
        },
        beforeSend: function() {
            $("a[bid='" + bid + "']").attr("disabled", "disabled");
        },
        success: function(data) {
            if (data.code == 100) {
                $("a[bid='" + bid + "']").text('取消收藏');
            } else if (data.code == 101) {
                $("a[bid='" + bid + "']").text('加入我的书架');
            } else if (data.code == -102) {
                jalert("通知", data.msg,
                function() {
                    goToLogin($("#hidsign").val());
                });
            }
        }
    }).always(function() {
        $("a[bid='" + bid + "']").attr("disabled", false);
    });
}
hs_user_ajax.addZan = function(commentid, o) {
    var submiturl = hs_const_url.userajax;
    $.ajax({
        url: submiturl,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'addzan',
            commentid: commentid
        },
        beforeSend: function() {},
        success: function(data) {
            if (data.code == -102) {
                jalert("通知", data.msg,
                function() {
                    goToLogin(1);
                });
            } else if (data.code == -115) {
                jalert("通知", data.msg, null);
            } else if (data.code == 108) {
                $("#" + o + commentid).text(parseInt($("#" + o + commentid).text()) + 1);
            }
        }
    }).always(function() {});
}
hs_user_ajax.sendReply = function(c, b) {
    hideFace();
    var content = $.trim($("#txtReply" + c).val());
    if (content.length == 0) {
        $("#txtReply" + c).css('background-color', 'rgb(255, 238, 238)');
        setTimeout("$('#txtReply" + c + "').css('background-color', '');", 800);
        return;
    }
    var submiturl = hs_const_url.bookajax;
    $.ajax({
        url: submiturl,
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            method: 'addreply',
            commentid: c,
            bid: b,
            content: content
        },
        beforeSend: function() {
            $("#btnSendReply" + c).attr("disabled", "disabled");
        },
        success: function(data) {
            if (data.code == -102) {
                jalert("通知", data.msg,
                function() {
                    goToLogin(1);
                });
            } else if (data.code == -121) {
                jalert("通知", data.msg, null);
            } else if (data.code == 111) {
                jalert("通知", data.msg, null);
            }
        }
    }).always(function() {
        $("#btnSendReply" + c).attr("disabled", false);
    });
}
function initSpacehead() {
    if ($("#hidPageType").val() == "spacehead") {
        if (window.userInfo != undefined) {
            if (window.userInfo.uid == $("#hidSpaceHeadUid").val()) {
                $("#divUserHeadShare").hide();
                $("#divUserHeadCenter").show();
            } else {
                $("#divUserHeadCenter").hide();
                $("#divUserHeadShare").show();
            }
        } else {
            $("#divUserHeadCenter").hide();
            $("#divUserHeadShare").show();
        }
    }
}
function showShare(needctrl) {
    if (needctrl == 1) {} else if (needctrl == 2) {
        var top = $("#divUserHeadShare").offset().top;
        var left = $("#divUserHeadShare").offset().left;
        $("#divShare").css("left", (left + 855)).css("top", (top + 40));
    }
    if ($("#divShare").css("display") == "none") {
        $("#divShare").fadeIn(fadeinTime);
    } else {
        $("#divShare").fadeOut(fadeoutTime);
    }
    $("body").click(function() {
        if ($("#divShare").css("display") == "block") {
            $("#divShare").fadeOut(fadeoutTime);
        }
    });
}